Do @property attributes not allow postincrement operators

Jamie notme at gmail.com
Sun Apr 14 01:54:39 UTC 2019


Do @property attributes not allow postincrement operators?

import std.stdio;

struct Foo {
     @property bar() { return 10; }
     @property bar(int x) { writeln(x); }
}

void main()
{
     Foo foo;
     writeln(foo.bar); // actually calls foo.bar();
     foo.bar = 10; // calls foo.bar(10);

     // following doesn't work
     foo.bar++; // would expect this to call foo.bar(foo.bar() + 
1);
     // have to use:
     foo.bar = foo.bar + 1;
     writeln(foo.bar);
}


More information about the Digitalmars-d-learn mailing list