0

I know that inheriting virtually would solve the diamond problem but am still not convinced. If the two-child classes are inheriting virtually and you override a method in two child classes, and you have a class let's say "class D" that is inheriting from both child classes, now if you call that method from the object of class D, still it is ambiguous to which implementation the compiler would choose. My point is this virtual inheritance, only works if you are not overriding the methods in the 2 child classes. Am I missing anything?

navid
  • 27
  • 5
  • Good duplicate, but how can we be sure this will convince the asker? How can we be sure of anything? – user4581301 May 15 '22 at 23:36
  • Side note: Show code. People will explain with respect to the code shown, using the code shown. – user4581301 May 15 '22 at 23:37
  • This has nothing to do with virtual inheritance or diamond hierarchy. If you have two classes `Base1` and `Base2` that both have a member function `f`, and `class Derived : public Base1, public Base2 {};`, then of course `D d; d.f();` is ambiguous. Nothing changes if `Base1` and `Base2` in turn both derive from some base class - that neither helps nor hurts. – Igor Tandetnik May 15 '22 at 23:43

0 Answers0