What are the conflicts between structure and deconstruction and between father and son in C++ inheritance?
This article is to share with you about the construction and deconstruction of C++ inheritance and the conflict between father and son. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
one。 Construction and deconstruction in inheritance
Q: how do I initialize parent class members? What is the relationship between the parent constructor and the subclass constructor?
a. Construction of subclass objects
1. A subclass can define a constructor
two。 Subclass constructor-the inherited member process must be initialized (initialized directly by initialization list or assignment, and initialized by calling the parent class constructor)
b. How the parent constructor is called in the subclass
1. Default call-applies to no-parameter constructors and constructors that use default parameters
two。 Display calls-calls are made through initialization lists and apply to all parent class constructors
Code example
# include # include using namespace std;class Parent {public: Parent () {cout