fun with properties
teo
teo.ubuntu at yahoo.com
Wed Mar 23 05:48:05 PDT 2011
How can I use properties with increment/decrement and +=/-= operators?
I did following tests (the errors are from dmd v2.052):
class T
{
private int _x;
@property
public int x() { return _x; }
}
void main()
{
int[] a;
// case #1.1
a.length++; // Error: a.length is not an lvalue
// case #1.2
a.length += 1; // Ok
auto t = new T();
// case #2.1
t.x++; // Error: t.x() is not an lvalue
// case #2.2
t.x += 1; // Error: 't.x' is not a scalar, it is a @property int()
// Error: incompatible types for ((t.x) += (1)):
'@property int()' and 'int'
// case #2.3
t.x()++; // Error: t.x() is not an lvalue
// case #2.4
t.x() += 1; // Error: t.x() is not an lvalue
}
Basically I want to change the value of a member variable, which is
accessed only through a property.
It looks like that is partially possible with the length property of
dynamic arrays although they probably are implemented in a different way.
More information about the Digitalmars-d-learn
mailing list