In C++ multiple inheritance, how is the diamond problem, where a class inherits two copies of a common base, avoided?
Correct answer C. By using virtual inheritance for the common base class
Explanation
If B and C both derive from A and D derives from both B and C, D normally contains two separate A subobjects, causing ambiguity. Declaring class B : virtual public A and class C : virtual public A makes them share a single A subobject in D. The most-derived class is then responsible for constructing that virtual base.
Answer checked How we write and check questions
Discussion