On 2019-04-15 08:19:57 +0000, Ali ‡ehreli said:

'alias this' can do that:

Hi, I had the suspicion already...

struct IM;
struct C {
  IM *impl;
};

int cInit(C* self) {
   return 0;
}

class I {
     C handler;

     this(){cInit(&handler);}

   C* ptr() {               // <== ADDED
     return &handler;
   }

   alias ptr this;          // <== ADDED
}

void someFunc(C* self) {
}

void main() {
   I myI = new I();
   someFunc(myI);
}

Bingo, I didn't know that I can do an 'alias this' using a function and not only a type... pretty cool. So, with several of these I can setup implicit conversions to different types. Thanks.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster

Reply via email to