-
Notifications
You must be signed in to change notification settings - Fork 0
/
123.cpp
55 lines (55 loc) · 947 Bytes
/
123.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
// WAP to demonstrate the order of call of constructors and destructors in case of virtual base class .
#include <iostream>
using namespace std;
class A
{
public:
A()
{
cout << "Base Class constructor\n";
}
~A()
{
cout << "Base Class Destructor\n";
}
};
class B : virtual public A
{
public:
B()
{
cout << "Intermediate Base1 Class Constructor\n";
}
~B()
{
cout << "Intermediate Base1 Class Destructor\n";
}
};
class C : virtual public A
{
public:
C()
{
cout << "Intermediate Base2 Class Constructor\n";
}
~C()
{
cout << "Intermediate Base2 Class Destructor\n";
}
};
class D : public B, public C
{
public:
D()
{
cout << "Derived class constructor\n";
}
~D()
{
cout << "Derived Class Destructor\n";
}
};
int main()
{
class D Der;
}