-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtut43.cpp
72 lines (62 loc) · 931 Bytes
/
tut43.cpp
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
// Ambiguity Resolution in Inheritance in C++
#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()
{
Base2::greet();
}
};
class B
{
public:
void say()
{
cout << "Hello World. " << endl;
}
};
class D : public B
{
int a;
// D's new say() method will override base class's say() method.
public:
void say()
{
cout << "Hello my beautiful world. " << endl;
}
};
int main()
{
// Ambiguity 1
// Base1 base1obj;
// Base2 base2obj;
// base1obj.greet();
// base2obj.greet();
// Derived d;
// d.greet();
// Ambiguity 2
B b;
b.say();
D d;
d.say();
return 0;
}