Properties
Yigal Chripun
yigal100 at gmail.com
Fri Jan 9 06:16:06 PST 2009
Michel Fortin wrote:
> On 2009-01-09 05:47:26 -0500, Yigal Chripun <yigal100 at gmail.com> said:
>
>> that's solvable. as I noted in a previous post, a property seems to me
>> to be mainly syntax sugar for a struct like in the following snippet:
>>
>> class A {
>> struct Prop {
>> int internal;
>> int opCall() { return internal; }
>> void opAssign(int value) { internal = value; }
>> }
>> public Prop prop;
>> ...
>> }
>
> Hum, that doesn't really work. Getter and setters of the property have
> access to the whole class scope, and can call functions of that class.
> If you wanted to extract a property from a class, you'd have to do it by
> keeping a pointer to the class, not the property's value:
>
> class A {
> private int internal;
> struct Prop {
> A outerClass;
> int opCall() { return outerClass.internal; }
> void opAssign(int value) { outerClass.internal = value; }
> }
> public Prop prop;
> }
>
>
instead of manually doing it within the struct just do s/struct/class to
my code. this will solve it since inner classes have an "outer" pointer
to the containing class instance.
I wasn't trying to give the best and most general solution, just to
point out that there is a straight forward solution to this.
More information about the Digitalmars-d
mailing list