The first type is that the class member has a member as a class object and the member's class contains the default constructor. Then, the C ++ compiler will help you generate a default constructor for this class, it is used to call the constructor of its member object to complete the initialization structure of the member. It should be emphasized that if the member's class does not provide the default constructor, the C ++ compiler will not help you generate the default constructor of the class.
The second case is that the base class of this class has the default constructor. The C ++ compiler will also help you generate the default constructor of the derived class to call the default constructor of the base class and complete the initialization of the base class. In addition, it should be emphasized that if the base class does not provide this default constructed function, the C ++ compiler will not generate the default constructor for the derived class (here there are two meanings: first, the base class does not have any form of constructor. Second, the base class has other forms of non-default constructor. Of course, this type is not compiled, and the truth is obvious ).
The third case is that there are virtual functions in the class, then the C ++ compiler will generate the default constructor for you to initialize the virtual table (virtual function table vftable ).
The fourth case is that there is a virtual base class, so the C ++ compiler will generate a default constructor for you to initialize the virtual base class table (vbtable ).
In the following example, the compiling fails because the default constructor is not provided in the base class A. After adding the default constructor to the base class A, the compilation passes ..
# Include "iostream" using namespace STD; Class A {public: A () {}// the default constructor can be added to the base class. A (int c) {x = C; cout <"A" <Endl;} void fun () {cout <"in a fun" <Endl;} PRIVATE: int x ;}; Class B: Public A {public: B (INT c) {Y = C; cout <"B" <Endl ;} void fun () {cout <"in B fun" <Endl;} PRIVATE: int y ;}; int main (void) {A * A = new B (2 ); system ("pause"); Return 0 ;}