Property discussion wrap-up
TommiT
tommitissari at hotmail.com
Thu Jan 31 08:56:56 PST 2013
On Thursday, 31 January 2013 at 16:44:03 UTC, TommiT wrote:
> T t;
> foo(t.myProp); // foo(t.myProp.opGet());
> auto v = t.myProp; // int v = t.myProp.opGet();
> t.myProp = 41; // t.myProp.opAssign(41);
> t.myProp += 1; // t.myProp.opAssign!"+"(41);
> assert(t.myProp.isCorrect());
>
> immutable T t2;
> t2.myProp.sayWhat(); // error: cannot call a non-const property
> // method of an immmutable variable t2
(CONT'D)
t.myProp *= 2; // error: can't assign to an rvalue int
It tries to call:
t.myProp.opGet() *= 2;
...because T.myProp doesn't define a *= operator. So, it becomes
one of those "naked" uses of a property.
More information about the Digitalmars-d
mailing list