Pointer to variables in D

jerro a at a.com
Thu Apr 26 03:23:36 PDT 2012


> This is the closest thing:
>
> ---
> struct C {
>  int x;
>  int* ptr() @property { return &x; }
> }
>
> C foo;
> *foo.ptr = 10;
> assert(foo.x = 10);
> ---

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.


More information about the Digitalmars-d-learn mailing list