-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultipleinheritance.cpp
41 lines (41 loc) · 992 Bytes
/
multipleinheritance.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
using namespace std;
class Base1{
protected:
int base1int;
public:
void set_base1int(int a){
base1int = a;
}
};
class Base2{
protected:
int base2int;
public:
void set_base2int(int a){
base2int = a;
}
};
class Derived : public Base1, public Base2{
public:
void show(){
cout << "The value of base 1 is: " << base1int << endl;
cout << "The value of base 2 is: " << base2int << endl;
cout << "The sum of base1 and base2 is: " << base1int + base2int << endl;
}
};
/*
Since we inherited in public mode the inherited base class will look something like this:
Data members:
base1int --> protected
base2int --> protected
Member functions:
set_base1int --> public
set_base2int --> public
*/
int main(){
Derived a;
a.set_base1int(20);
a.set_base2int(30);
a.show();
}