When a user does not define a constructor for a class, the compiler does not have a default constructor for each class, and only synthesizes the default constructor when the compiler requires it. The compiler synthesizes the default constructors just to meet the compiler's needs, not to the programmer's needs (for example, the initialization of a member variable requires a programmer to define a constructor). 1, the object contains the object with the default constructor
Class a{public
:
A ();
}
Class b{public
:
a A;
}
In the group B requires the compiler to synthesize the default constructor to invoke A's default constructor to define (does not help the programmer initialize) b own member variables, and built-in type variables are not required.
2, the parent class with a default constructor
Class a{public
:
A ();
}
Class B:public A
{
...
}
In an inheritance relationship, with compositing, the compiler needs to synthesize the default constructor class for B to call A's default constructor.
3, with a virtual function of the class
Class with a virtual function, the compiler synthesizes a virtual table that holds a virtual function pointer as needed. 4, virtual inheritance of the class