Virtual inheritance is a syntax in the C ++ programming language, so that if a derived class inherits a base class multiple times, only one copy of the base class is in the derived class object.
Virtual inheritance
Right!
Virtual inheritance is a syntax in the C ++ programming language, so that if a derived class inherits a base class multiple times, only one copy of the base class is in the derived class object.
- Name
- Virtual inheritance
- Name
- Virtual Inheritance
- Belong to
- C ++
- Grammar
- class derived class: virtual base class 1
C ++ uses Virtual Inheritance, so that if the derived class inherits the base class multiple times, only one copy of the base class is in the derived class object.
Syntax of virtual inheritance:
class derived classes: virtual base class 1, virtual base class 2, ..., virtual base class n {
... / Derived class member declaration
}; Multiple inheritance construct execution order
First, the constructors of the virtual base classes are executed, and the constructors of multiple virtual base classes are constructed in the order of inheritance;
The constructors of the base class are executed, and the constructors of multiple base classes are constructed in the order of inheritance;
The constructors of member objects are executed, and the constructors of multiple member objects are constructed in the order of declaration;
Execute the derived class's own constructor;
Destructuring is performed in the reverse order of construction;