Definition: The constructor used to create an object when an explicit initial value is not provided.
Example:
Class TestClass
{
Private
int m_a;
int m_b;
Public
TestClass (); Default constructor 1
TestClass (int a,int b); constructor function
TestClass (int a=10,int b=5); Default constructor 2
};//Note that the actual use of a class in the default constructor 1 and the default constructor 2 can only appear 1, here just to illustrate
Summarize:
1) The default constructor is primarily used to complete the initialization of this form: TestClass A; In this case, if the programmer does not define a default constructor, the compiler will make an error.
2) If the programmer does not provide any constructors, then the compiler will automatically generate a default constructor.
3) There are two ways to define a default constructor, one of which is the default constructor 1 in the example above, a parameterless constructor, and the default constructor 2 in the example above, which defines a constructor where all formal parameters have default values.
4) A class can have only one default constructor.
5) If the programmer provides any form of constructor, then the compiler will no longer provide a default constructor.
C + + Learning Note Constructor (a) default constructor