When I implement the below code the o/p I get is:
mother: int parameter: 20
father: int parameter: 30
son: int parameter: 10
Which is perfectly fine. My question is: Is there a way to specify the values for the parent class constructors from the main function at the time when the child class object is created.
i.e. can we specify what values should be passed to the parent class constructors through this invocation==> baby max(10);
#include <iostream>
usingnamespace std;
class mother
{
public:
mother ()
{ cout << "mother: no parameters\n"; }
mother (int a)
{ cout << "mother: int parameter: "<<a<<endl; }
};
class father
{
public:
father ()
{ cout << "father: no parameters\n"; }
father (int a)
{ cout << "father: int parameter: "<<a<<endl; }
};
class baby : public mother,public father
{
public:
baby (int a) : mother (20),father (30)
{ cout << "son: int parameter: "<<a<<endl; }
};
int main () {
baby max(10);
return 0;
}