One: constructor function
Form: Derived class Name:: Derived class Name: base class name 1 (parameter 1), base class Name 2 (Parameter 2), ... base class name N (parameter n), data member 1 (parameter 1), data member 2 (parameter 2), ... data member n (parameter n) {
Description of the various operations
}
Execution procedure: First executes the constructor of the base class, then assigns the data member, finally executes the function body.
The order in which the base class name and data members are executed is determined by the order in which they are declared in the definition of the derived class, so their order is arbitrary, but for readability it is best to write sequentially.
If the base class has only a default constructor, the base class name and parameter table can be used without writing.
Two: copy constructor
The form of a constructor for a derived class is illustrated with an example:
Derived::D erived (derived&v): Base1 (v) {...}
Careful words will find that the formal parameters of Base1 and derived are the same as C, where the type compatibility rules are used.
Three: Destructors
The form of the destructor of the derived class and the destructor of the ordinary class are identical in form, and the order of execution and the constructor of the derived class are executed exactly the opposite, that is, the function body is executed first, then the destructor of the member is executed, and the destructor of the base class is executed finally.
This is my understanding of the constructors and destructors of derived classes.
Understanding of constructors and destructors for derived classes in C + +