property syntax problems
Alex Burton
alexibu at mac.com
Thu Feb 5 03:55:46 PST 2009
Hi,
I just found a bug that comes out of the property syntax.
The property syntax is great in that it allows a smooth transition from simple code dealing with public member variables to the use of interfaces without needing to update the client code.
i.e. A.bob = 1 can stay as A.bob = 1 when bob changes from being an int to being void A::bob(int i)
instead of changing to A.bob(1).
But this can introduce the bug I show below.
Proposal :
If the temporary returned by the property syntax getter function is modified, then the corresponding setter function needs to be called with the temporary as argument.
struct A
{
int i;
int j;
};
class B
{
A mA;
public:
A a() { return mA; }
void a(Atom a) { mA = a; }
};
int main()
{
B b;
b.a.j = 10; // error b.a is a temporary.
}
More information about the Digitalmars-d
mailing list