Search code examples
c++inheritancemultiple-inheritancevirtual-inheritance

Using virtual inheritance on "final" classes in unfinished class hierarchies


Is there any harm or is it considered bad design to preemptively derive virtually classes in an unfinished class hierarchy that are currently "at the bottom" (i.e., the most derived)? Is there a good reason one would want to wait until there was actually a need for virtual inheritance (i.e., when someone decides to extend the hierarchy and it results in a diamond)?


Solution

  • I would avoid virtual inheritance until actually needed. When you use virtual inheritance you are leaking part of the abstractions that you build on your class, and in particular how you initialize your base class, by forcing the call to the virtual base to the most derived type.