C++ (Qt)class CMyContext { ... CMyPixel mPixel;}; void DoSomething( CMyPixel * pix );
void DoSomething(CMyPixel *){ union X { void* offset; CMyPixel* CMyContext::* pointer; }; X x; x.pointer = &CMyContext::mPixel; // далее юзайте x.offset ...}
C++ (Qt)/* Offset of member MEMBER in a struct of type TYPE. */ #ifndef __cplusplus #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) #else /* The cast to "char &" below avoids problems with user-defined "operator &", which can appear in a POD type. */ #define offsetof(TYPE, MEMBER) \ (__offsetof__ (reinterpret_cast <size_t> \ (&reinterpret_cast <const volatile char &> \ (static_cast<TYPE *> (0)->MEMBER)))) #endif /* C++ */
C++ (Qt)void DoSomething( CMyPixel * pix ){ CMyContext * ctx = 0; ctx = (CMyContext *)((char *) pix - (size_t) &ctx->mPixel); printf("pix = %p, ctx = %p\n", pix, ctx);}
C++ (Qt) #define offsetof(TYPE, MEMBER) \ (__offsetof__ (reinterpret_cast <size_t> \ (&reinterpret_cast <const volatile char &> \ (static_cast<TYPE *> (0)->MEMBER)))) #endif /* C++ */
C++ (Qt)CMyPixel::CMyPixel( const CMyPixel & ){//.. ???}