Properties
Miles
_______ at _______.____
Fri Jan 9 04:12:48 PST 2009
Chad J wrote:
> I agree, though let's not fool ourselves, there is at least one corner case:
>
> property int foo
> {
> get{ ... }
> set{ ... }
> }
>
> auto bar = &foo;
> what happens when someone writes this?
Yes, this is a corner case. If the getter is not set to return an
lvalue, that makes as much sense as trying to get a reference from an
rvalue, like &5.
> I've tried this in C# and it is simply forbidden. I am OK with this,
> though I'd love it if there was a better way.
That is expected behavior. Although able to emulate variables,
properties are not variables, and neither functions. They could be seen
as a collection of delegates. In some cases, the compiler may allow you
to retrieve individual delegates from the property through some syntax,
like:
auto bar = & property(foo).get;
More information about the Digitalmars-d
mailing list