-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path43_a_Ambiguity_Resolution.cpp
More file actions
50 lines (36 loc) · 917 Bytes
/
Copy path43_a_Ambiguity_Resolution.cpp
File metadata and controls
50 lines (36 loc) · 917 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
// Ambiguity 1
#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...!!
};
int main()
{
// Ambiguity 1
Base1 base1obj;
Base2 base2obj;
// base1obj.greet(); --> This will definitely work
// base2obj.greet(); --> This will definitely work
Derived derivedObj;
derivedObj.greet();
return 0;
}