对象解引用成员指针时,对象的动态类型不包含成员指针引用的成员
C++-Undefined-Behavior-42
示例:
struct A { int a; };
struct B { int a, b; };
int foo(A* pa) {
B* pb = (B*)pa;
int B::* m = &B::b;
return pb->*m; // Undefined behavior
}
依据
ISO/IEC 14882:2003 5.5(4)-undefined
ISO/IEC 14882:2011 5.5(4)-undefined