C + + Defaul construct: default constructor (default constructor)
Definition: The first constructor has no parameters, that is, a () Form
All parameters of the second constructor are provided by default values, A (int a=0,int b=0)
The compiler adds a condition for the default constructor: If you create a class you do not write any constructors, the system automatically generates the default parameterless constructor, the function is empty, nothing is done (this constructor is only a case where the trival
Relationships of derived classes and base classes:
We typically say derived classes and base classes, when we call a custom constructor for a derived class, the derived class automatically calls the default construct function in the base class, and cannot call the other constructors in the base class
classFoo {Private: intVal; Public: Foo (): Val (9){}}; classBar: PublicFoo { Public: Char*str; inti; Bar (intIChar*5) {i=i; STR=s; }}; //cannot pass because the bar derived class cannot call the Defalut function in the base class because there is noclassFoo {Private: intVal; Foo (inti): Val (i) {}}; classBar: PublicFoo { Public: Char*str; inti; Bar (intIChar*s) {i=i; STR=s; }};
classFoo {Private: intVal; Public: Foo (inti): Val (i) {} Foo (): Val (6){}}; classBar: PublicFoo { Public: Char*str; inti; Bar (intIChar*1) {i=i; STR=s; }}; When you define both the normal constructor and the default construct function in base, the derived class can invoke the
Problems with the C + + default constructor