@property - take it behind the woodshed and shoot it?
Adam D. Ruppe
destructionator at gmail.com
Thu Jan 24 14:15:38 PST 2013
On Thursday, 24 January 2013 at 22:04:02 UTC, Andrei Alexandrescu
wrote:
> Properties are DATA, well except when you need to pass fields
> by reference etc. at which point the syntactic glue comes
> unglued.
An enum or a literal can't be passed by reference or otherwise
have the address taken either, but we don't argue about if
they're data or not, and don't change barely related parts of the
language over them.
void foo(ref int a) {}
int b;
foo(b); // ok
foo(10); // nope
test.d(6): Error: function test.foo (ref int a) is not callable
using argument types (int)
test.d(6): Error: constant 10 is not an lvalue
No big deal. Similarly:
enum c = 20;
foo(c);
test.d(12): Error: function test.foo (ref int a) is not callable
using argument types (int)
test.d(12): Error: constant 20 is not an lvalue
Note: the error message betrays some truth about enum's
implementation.... but who cares.
And finally:
@property int bar() { return 0; }
foo(bar);
test.d(9): Error: function test.foo (ref int a) is not callable
using argument types (int)
test.d(9): Error: bar() is not an lvalue
Like the enum, we see a hint in the error message that the
compiler is doing a little magic... but who cares.
More information about the Digitalmars-d
mailing list