Q1: given virtual inheritance, the derived class only gets one instance of the bs
object, yet there are three implementations of name()
, and it doesn't know which to use. If you derive non-virtually, then there are three bs bases embedded in the A, B and D classes, each of which can override the implementation. Alternatively, you have found that you can replace the ambiguous implementations after virtual inheritance with one implementation in C.
Q2: in the non-virtual situation, you have three bs
bases in the embedded A, B and D objects: which of these do you want a pointer to? It's ambiguous so you get the error. If you used virtual inheritance, then there's only one bs
base object and you can get a pointer to it.
To illustrate:
VIRTUAL NON-VIRTUAL
. bs bs bs bs
. / | \ | | |
. A B D A B D
. \ | / \ | /
. C C
On the left, your problem was C
didn't know which of A::name()
, B::name()
or D::name()
to use unless you overrode all three in C
.
On the right, your problem was that b* my_b_ptr
didn't know which bs
base to point at.