get Class from Pointer of member

StefanvT stefanvt at gmx.de
Thu May 24 05:29:54 PDT 2012


Hi,
I'm totally new to D. But it looks very interesting :-)
I normally develop in C++.

I have such a function in C++:

template<class CB,class FIELD>
inline CB* get_class_from_field( FIELD CB::*field, FIELD* mp) {
     return reinterpret_cast<CB*>(
             reinterpret_cast<char*>(mp) -
             
reinterpret_cast<ptrdiff_t>(&(reinterpret_cast<CB*>(0)->*field)));
}


Here I come with a pointer to a class member and can calculate 
the pointer to the class, where the member is within. (Nothing 
spectacular in c++)

Is this also possible in D?
I noticed that it's not very easy to get a member pointer on the 
heap. Isn't it?

thank you & best regards,
Stefan


More information about the Digitalmars-d-learn mailing list