Because with multiple inheritance you can't cast directly to a upper class without passing by the child class. This because a void*
doesn't contain any information about the layout in memory of the various classes that form your final Grand*
instance.
To fix this you need indeed to cast it to it's runtime type:
Base *b = (Base*)(Grand*)v;
b->f();
Think about the fact that the layout could have Base
in a different position. Think about another
class Grand2 : public Something, public Else, public Base1, public Child {
..
}
Now, where is Base
located inside the Grand2
structure? In a different position compared to Grand
. How could the compiler know the correct offset starting from just a pointer to a non specified class (which could be a Grand
or a Grand2
)?