Pointer to variables in D

jerro a at a.com
Thu Apr 26 03:25:31 PDT 2012


> Now you can also do:
>
> struct C
> {
>   int x;
> }
>
> int* ptr() @property { return &x; }
>
> C foo;
> *foo.ptr = 10;
> assert(foo.x = 10);
>
>
> if you can't or don't want to change C.

int* ptr() @property { return &x; }

should be

int* ptr(ref C c) @property { return &c.x; }


More information about the Digitalmars-d-learn mailing list