# include "string"
using namespace std;
The class father
{
Public:
Father (a string s, int a)
{name=s; Tell=a; Print (); cout<" Leave the base class constructor "& lt;
~ the father () {cout<" \ n release base class object \ n "; }
Void the print () {cout
String name; Int tell;
};
The class son: public father
{
Public:
Son (string a, int b, int c);
~ son () {cout<" Release the subclass object \ n \ n "& lt;
Private:
Int weight;
};
Son: : son (string a, b int, int) c
{
Name=a;
Tell=b;
cout<" "In the subclass constructor & lt;
}//* *
Void son: : print1 ()//why do you want to add void here
{
Father: : print ();
cout<" Weight: "& lt;
Int main ()
{
Son a (" Mike ", 180);
//Amy polumbo rint1 ();
cout<" After "& lt;
}
CodePudding user response:
'father' : no appropriate default constructor availableCodePudding user response:
1. The call to subclass constructor when need to call the superclass constructorFrom your parent class is also the father to see father class no default is father (); The implementation of the
So in the subclass constructor needs to explicitly call father's constructor
As follows:
Son: : son (string a, b int, int) c: father (a, b)
{
Name=a;
Tell=b;
Cout & lt; <"In the subclass constructor" & lt;
}/* */