The C ++ compiler combines the conditions of the default constructor (the default copy constructor is the same), and the constructor copies the constructor.
When a user does not define a constructor for a class, the compiler does not combine each class into a default constructor,The default constructor is synthesized only when the compiler needs it. The synthesis of default constructor by the compiler only meets the compilation needs of the compiler, rather than the needs of programmers (for example, the initialization of member variables also requires programmers to define constructor).
1. The object contains objects with Default constructors
Class A {public: A ();} class B {public: A ;}
In combination, B needs the compiler to synthesize the default constructor to call the default constructor of A to define (does not help programmers to initialize) B's member variables, built-in type variables are not required.
2. The parent class contains the default constructor.
Class A {public: A ();} class B: public {...}
In the inheritance relationship, the compiler needs to call the default constructor A for B's synthesis of constructor classes.
3. classes with virtual functions
For classes with virtual functions, the compiler synthesize a virtual table that stores virtual function pointers as needed.
4. Virtual inheritance class
In the C ++ Single Instance class, why not declare the copy constructor? Will the compiler automatically generate a copy constructor?
If no replication constructor is defined, the compiler will merge one.
Merging and copying constructor: copying members one by one, where value type members directly copy, and class type members call their copying constructor.
If the replication constructor is not defined in the C ++ class, does the system define the default replication constructor?
As you understand, if you do not define a replication constructor, the system will generate a default replication constructor for you, but this is not always a good thing, when your class contains private data members of the pointer type, the default copy constructor is dangerous because it directs the pointers of both objects to the same memory area.