Downcast in a diamond hierarchy
问题 Why static_cast cannot downcast from a virtual base ? struct A {}; struct B : public virtual A {}; struct C : public virtual A {}; struct D : public B, public C {}; int main() { D d; A& a = d; D* p = static_cast<D*>(&a); //error } g++ 4.5 says: error: cannot convert from base ‘A’ to derived type ‘D’ via virtual base ‘A’ The solution is to use dynamic_cast ? but why. What is the rational ? -- edit -- Very good answers below. No answers detail exactly how sub objects and vtables end up to be