-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinhvirtualclass.cpp
More file actions
51 lines (46 loc) · 912 Bytes
/
inhvirtualclass.cpp
File metadata and controls
51 lines (46 loc) · 912 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
#include <iostream>
using namespace std;
class Person {
public:
Person() {
cout << "Person constructor called.\n";
}
void greet() {
cout << "Hello from Person.\n";
}
~Person() {
cout << "Person destructor called.\n";
}
};
class Student : virtual public Person {
public:
Student() {
cout << "Student constructor called.\n";
}
~Student() {
cout << "Student destructor called.\n";
}
};
class Teacher : virtual public Person {
public:
Teacher() {
cout << "Teacher constructor called.\n";
}
~Teacher() {
cout << "Teacher destructor called.\n";
}
};
class TA : public Student, public Teacher {
public:
TA() {
cout << "TA constructor called.\n";
}
~TA() {
cout << "TA destructor called.\n";
}
};
int main() {
TA obj;
obj.greet(); // No ambiguity
return 0;
}