Inner struct accessing host member
Philippe Sigaud via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Aug 5 22:48:29 PDT 2014
On Tuesday, 5 August 2014 at 23:47:00 UTC, Artur Skawina via
Digitalmars-d-learn wrote:
>> Is there any way I can gain access on i inside B?
>
> Not directly, but as you ask for /any/ way -- yes:
>
> struct B
> {
> void foo() { outer.i ~= 1; }
> ref A outer() inout @property { return
> *cast(A*)(cast(void*)&this-A.b.offsetof); }
> }
>
> Note this will work only as long as you have just one B
> instance in A and B is never created or copied outside of A.
OK. I have en entire graph, whose nodes are Bs inside A. So that
might not be totally appropriate for me. Thanks anyway, I always
forget about offsetof
More information about the Digitalmars-d-learn
mailing list