Transparent cast from class to member pointer?

diniz diniz at posteo.net
Sun Apr 14 20:01:27 UTC 2019


Le 14/04/2019 à 20:03, Robert M. Münch via Digitalmars-d-learn a écrit :
> struct IM;
> struct C {
>   IM *impl;
> };
> 
> int cInit(C* self);
> 
> class I {
>      C handler;
> 
>      this(){cInit(&handler);}
> }
> 
> Is there a simple way that I can use handler without the address-of operator and 
> automatically get *impl?
> 
> Something like:
> 
> class I {
>      C handler;
> 
>      this(){cInit(handler);}
> }
> 
> And later can use I in a way like this without having to define/write explicit 
> casts everywhere?
> 
> someFunc(C* self);
> 
> I myI;
> someFunc(myI);

Do you have a clear and correct view of what you want to express, of the 
application? How does it look (for us), if you replace IM, C, impl, cInit, I, 
handler, with meaningful (and correctly chosen) terms?

-- 
diniz {la vita e estranj}


More information about the Digitalmars-d-learn mailing list