In the question about invoking virtual methods in ctors and dtors , the following code fragment from the C ++ standard is given:
struct V { virtual void f(); virtual void g(); }; struct A : virtual V { virtual void f(); }; struct B : virtual V { virtual void g(); B(V*, A*); }; struct D : A, B { virtual void f(); virtual void g(); D() : B((A*)this, this) { } }; B::B(V* v, A* a) { f();
My question is: why calling a->f() in B ctor is this undefined behavior? We can safely assume that a already highlighted before switching to B ctor, so why doesn't it work correctly?
V * v = new V(); A * a = new A(); B * b = new B(v, a);
source share