Taking offset of a reference member (non PODs)
问题 Here is the code snippet #include <iostream> struct Z { Z():x(0),y(0),z(x){} ~Z(){} int x; int y; int &z; // Reference member }; template <typename Type, typename C, typename M> size_t Offsetof (M C::* ptr_to_member) { Type type; return reinterpret_cast<char*> (&(type.*ptr_to_member)) - reinterpret_cast<char*> (&type); } int main() { std::cout << Offsetof<Z>(&Z::x); // works std::cout << Offsetof<Z>(&Z::y); // works std::cout << Offsetof<Z>(&Z::z); // doesn't work } We cannot create pointer