@property
Fyodor Ustinov via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Nov 9 14:42:15 PST 2015
On Monday, 9 November 2015 at 22:06:22 UTC, Alex Parrill wrote:
> Check out the following code:
>
>
> struct Test {
> int foo() {
> return 2;
> }
> int bar() @property {
> return 2;
> }
> }
>
> pragma(msg, typeof(Test.foo)); // Prints int(); i.e. a
> zero-argument function that returns an int
> pragma(msg, typeof(Test.bar)); // Prints int; i.e. a plain int
But the compiler is lying!
void main() {
auto a = Test();
auto aa = &a.bar; // if type of a.bar is int
writeln(*aa); // why: Error: can only * a pointer, not a 'int
delegate() @property'
}
> AFAIK when @property was introduced, it was expected that after
> a deprecation period, calling non-property functions without
> parenthesis would be invalid, but I don't think that panned
> out. It's still good for documentation.
If this feature will be removed, it will be very lacking code,
like:
writeln = "Hello, world!";
:)
WBR,
Fyodor.
More information about the Digitalmars-d-learn
mailing list