Derived classes and inheritance
This protects a Member from being accessed by the member functions of the derived class, but is hidden from the outside and cannot be accessed by external functions.
When creating a derived class object, first execute the base class constructor, and then execute the constructor of the derived class. When revoking the object of the derived class, first execute the destructor of the derived class, then execute the destructor of the base class.
When the base class contains constructors with parameters, the derived class must define constructors.
If the base class of a derived class is also a derived class, each derived class only needs to be responsible for its direct construction of the base class, which is traced in turn.
Virtual base class
Solve the Problem of ambiguity. If a derived class is derived from multiple base classes and these base classes have a common base class, when this derived class accesses members of this common base class, this vulnerability may cause ambiguity.
Class base1: virtual public base {}
If the same level contains both the virtual and non-virtual base classes, you should first call the constructor of the virtual base class before calling the constructor of the non-virtual base class, finally, call the constructor of the derived class.
Class X: Public y, virtual public Z {}