ambiguity in inheritance c 2b 2b

Solutions on MaxInterview for ambiguity in inheritance c 2b 2b by the best coders in the world

showing results for - "ambiguity in inheritance c 2b 2b"
Filippo
23 Jun 2018
1
2       #include<iostream.h>
3       #include<conio.h>
4
5       class ClassA
6       {
7              public:
8              int a;
9       };
10
11       class ClassB : public ClassA
12       {
13              public:
14              int b;
15       };
16       class ClassC : public ClassA
17       {
18              public:
19              int c;
20       };
21
22       class ClassD : public ClassB, public ClassC
23       {
24              public:
25              int d;
26       };
27
28       void main()
29       {
30
31			  ClassD obj;
32
33			  //obj.a = 10;                   //Statement 1, Error occur
34			  //obj.a = 100;                 //Statement 2, Error occur
35
36			  obj.ClassB::a = 10;        //Statement 3
37			  obj.ClassC::a = 100;      //Statement 4
38
39			  obj.b = 20;
40			  obj.c = 30;
41			  obj.d = 40;
42
43			  cout<< "\n A from ClassB  : "<< obj.ClassB::a;
44			  cout<< "\n A from ClassC  : "<< obj.ClassC::a;
45
46			  cout<< "\n B : "<< obj.b;
47			  cout<< "\n C : "<< obj.c;
48			  cout<< "\n D : "<< obj.d;
49
50	   }
51
52   Output :
53
54              A from ClassB  : 10
55              A from ClassC  : 100
56              B : 20
57              C : 30
58              D : 40
59
60