I figured out by trying that
struct PropertyTest
{
@property int x() { return val; }
@property void x( int newVal ) { val = newVal; }
void test()
{
int j;
j = x;
x = 5;
}
private:
int val;
}
does exactly the same when I leave the @property out. Everything compiles fine. What’s the point then for declaring functions as @property?
BTW, I’m using the dmd2 compiler.
The reason they work without
@propertyis because@propertywas added after they allowed the property method syntax. Adding-propertyto your DMD command line enforces use of@propertyannotation. It’s not the default for backward compatibility reasons. Someday it will become the default (or so they say) so it’s best to compile with-propertyto ensure you are annotating properly.