-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path40Ambiguity_Inheritance.cpp
More file actions
63 lines (52 loc) · 900 Bytes
/
40Ambiguity_Inheritance.cpp
File metadata and controls
63 lines (52 loc) · 900 Bytes
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
#include <iostream>
using namespace std;
class Base1
{
public:
void greet()
{
cout << "how are you? " << endl;
}
};
class Base2
{
public:
void greet()
{
cout << "Kaise ho? " << endl;
}
};
class Derived : public Base1, public Base2
{
int a;
public:
void greet()
{
Base1 ::greet(); // Ambiguity Solving
}
};
class B{
public:
void say(){
cout<<"Hello World "<<endl;
}
};
class D : public B{
public:
void say(){
cout<<"Hello World 2 "<<endl;
}
};
int main()
{
Base1 base1obj;
Base2 base2obj;
base1obj.greet();
base2obj.greet();
Derived num1;
num1.greet();
D d;
d.say(); // Here amiguity is auto resolved, as the class D have to function say(),
// and it choose the one which is not Inheritate but its own
return 0;
}