class Base { int type; };
class Derived1 : public Base { ... };
class Derived2 : public Base { ... };
class Container
{
public:
Derived1 f1;
Derived2 f2;
};
Container c;
size_t offset = (size_t) static_cast<Base*>( &reinterpret_cast<Container*>(0)->f2 );
Base* base = reinterpret_cast<Base*>( (size_t) c + offset ); // ok
Base Container::* ptr = &Container::f2; // compile error!
base = c.*ptr;
使用指向成员的指针获取指向Base的指针的任何有效方法是什么?