What is virtual inheritance conceptually, and what problem in inheritance hierarchies is it meant to address?
Last updated
Virtual inheritance (C++) ensures a base reached through multiple paths exists as a single shared subobject. This fixes the state-duplication side of the Diamond Problem.
Declaring
class B : virtual Aandclass C : virtual Agives D one A, so member access is unambiguous.Trade-offs: extra indirection and construction complexity. The most-derived class must initialize the shared virtual base.