Third, if a class inherits one or more classes that have virtual parents, the most derived class is responsible for constructing the virtual base class. In this case, Copier inherits Printer and Scanner, both of which have a PoweredDevice virtual base class. Copier, the most derived class, is responsible for creation of PoweredDevice. Note that this is true even in a single inheritance case: if Copier was singly inherited from Printer, and Printer was virtually inherited from PoweredDevice, Copier is still responsible for creating PoweredDevice.
https://www.learncpp.com/cpp-tutorial/128-virtual-base-classes/
本文深入探讨了在C++中,当一个类继承多个拥有虚拟基类的父类时,最派生类负责创建虚拟基类的实例。即使在单一继承情况下,如果派生类从具有虚拟基类的父类继承,派生类依然负责创建虚拟基类。
3524

被折叠的 条评论
为什么被折叠?



