-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path43_b_Ambiguity_Resolution.cpp
More file actions
63 lines (48 loc) · 1.03 KB
/
43_b_Ambiguity_Resolution.cpp
File metadata and controls
63 lines (48 loc) · 1.03 KB
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
// Ambiguity 2
#include<iostream>
using namespace std;
class Base1{
public:
void greet(){
cout << "How are you ?" << endl;
}
};
class Base2{
public:
void greet(){
cout << "Toh Kese hai app log ?" << endl;
}
};
// Now there is an ambiguity as both have function with same name so if we derive it in another class then which one it will pick?
// This creates an ambiguity
class Derived : public Base1, public Base2{
int a;
public:
void greet(){
Base2 :: greet();
}
// Defining that the greet should be taken from Base1 class...!!
};
class B{
public:
void say(){
cout << "Hello world!" <<endl;
}
};
class D : public B{
int a;
//D's new say() method will overide base class's say() method...!!
public:
void say(){
cout << "Hey World...Hello!" <<endl;
}
};
int main()
{
// Ambiguity 2
B objb;
objb.say();
D objd;
objd.say();
return 0;
}