Am 04.08.2010 12:11, schrieb Rory Mcguire:
Hi,
The code below is my beginning to attempt a class which implements any class
and throws an exception if one tries to access any member of that class.
Problem is that if I use:
auto a1 = noinit!(A)();
it works and accesses the int x() {...} member of the generated class, but
if I use:
A a1 = noinit!(A)();
it accesses A.x instead of the generated classes x.
So am I wrong in making a sub class have a member function which hides a
parent class's member variable or is the compiler wrong and it should
generate a call to generated sub class?
Thanks!!!
-Rory
Hi,
if x is a field (ie a member variable) it's statically bound. In your
example it is a field so it gets A.x of your subclass which is still
there becuase of the methoda of A which could use A.x.
Fields have to be statically bound because there's no covariance
guarateed with them. Use getters and setters instead.
BTW are @propertys statically or dynamically bound. They're kind of
both: fields and methods.
Mafi