Want to ascertain as to why static_cast cannot downcast from a virtual base.
Pls share ur ideas.
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
}
g++ 4.5 says
error: cannot convert from base ‘A’ to derived type ‘D’ via virtual base ‘A’
The solution appears to be using dynamic_cast but whats the rationale behind the same ???
49 weeks 12 hours ago