Virtual inheritance 虚继承
(重定向自Virtual base class)
- For inheritance of virtual functions, see virtual function.
Virtual inheritance is a technique used in C++, where a particular base class in an inheritance hierarchy is declared to share its member data instances with any other inclusions of that same base in further derived classes.
For example, if class A is normally (non-virtually) derived from class X (assumed to contain data members), and if class B is also derived from class X, and class C inherits from both classes A and B, it will contain two sets of the data members associated with class X (accessible independently, often with suitable disambiguating qualifiers). But if class A is virtually derived from class X instead, then objects of class C will contain only one set of the data members from class X.