Multiple inheritance program in C++.
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
| /*C++ program to demonstrate example of multiple inheritance.*/ #include <iostream> using namespace std; //Base Class - class A class A { private : int a; public : void get_a( int val_a){ a=val_a; } void put_a( void ){ cout << "value of a: " << a << endl; } }; //Base Class - class B class B { private : int b; public : void get_b( int val_b){ b=val_b; } void put_b( void ){ cout << "value of b: " << b << endl; } }; //Base Class - class C class C { private : int c; public : void get_c( int val_c){ c=val_c; } void put_c( void ){ cout << "value of c: " << c << endl; } }; //multiple inheritance, Derived Class - class final class final: public A, public B, public C { public : void printValues( void ) { //now, we can call member functions of class A,B,C put_a(); put_b(); put_c(); } }; int main() { //create object of final (derived class) final objFinal; /*read values of a,b and c - which are the private members of class A,B and C respectively using public member functions get_a(), get_b() and get_c(), by calling with the object of final class.*/ objFinal.get_a(100); objFinal.get_b(200); objFinal.get_c(300); //print all values using final::printValues() objFinal.printValues(); return 0; } |
value of a: 100 value of b: 200 value of c: 300