正在构造或析构的对象通过 . 或 -> 调用虚函数,而且该对象与当前构造或析构函数不属于同一个类或基类
C++-Undefined-Behavior-63
示例:
struct V {
virtual void foo();
virtual void bar();
};
struct A: virtual V {
void foo() override;
};
struct B: virtual V {
B(V*, A*);
void bar() override;
};
struct C: A, B {
C(): B((A*)this, this) {
}
void foo() override;
void bar() override;
};
B::B(V* v, A* a) {
v->bar(); // Well-defined, V is the base of B
a->foo(); // Undefined behavior, A is not a base of B
}
依据
ISO/IEC 14882:2003 12.7(3)-undefined
ISO/IEC 14882:2011 12.7(4)-undefined