#include <iostream>

struct V {
	virtual void f(){std::cout << __PRETTY_FUNCTION__ << std::endl;}
	virtual void g(){std::cout << __PRETTY_FUNCTION__ << std::endl;}
};
struct A : virtual V {
	virtual void f(){std::cout << __PRETTY_FUNCTION__ << std::endl;}
};
struct B : virtual V {
	virtual void g(){std::cout << __PRETTY_FUNCTION__ << std::endl;}
	B(V*, A*);
};
struct D : A, B {
	virtual void f(){std::cout << __PRETTY_FUNCTION__ << std::endl;}
	virtual void g(){std::cout << __PRETTY_FUNCTION__ << std::endl;}
	D() : B((A*)this, this) { }
};

B::B(V* v, A* a) {
	f(); // calls V::f, not A::f
	g(); // calls B::g, not D::g
	v->g(); // v is base of B, the call is well-defined, calls B::g
	a->f(); // undefined behavior, a’s type not a base of B
}

int main(){
    D d;
}