passing the value to base class constructor from derived class c 2b 2b

Solutions on MaxInterview for passing the value to base class constructor from derived class c 2b 2b by the best coders in the world

showing results for - "passing the value to base class constructor from derived class c 2b 2b"
Emilio
03 Jul 2018
1#include <iostream>
2#include<string>
3
4using namespace std;
5
6class Father{
7protected:
8    int height;
9public:
10    Father(){
11    cout << "constructor of father is called"<<endl;
12
13    }
14
15};
16class Mother{
17protected:
18    string skincolor;
19public:
20    Mother(){
21    cout << "constructor of mother is called"<<endl;
22
23    }
24
25};
26
27class Child : public Father,public Mother{
28public:
29    Child(int x,string color) : Father(),Mother(){
30    height = x;
31    skincolor = color;
32    cout << "child classs constructor"<<endl;
33    }
34void display(){
35cout << "height is "<<height<<" skin color is "<<skincolor<<endl;
36}
37};
38
39
40int main()
41{
42    Child anil(24,"while");
43    anil.display();
44    return 0;
45}
46
47