-
Notifications
You must be signed in to change notification settings - Fork 0
/
2VirtualDtor(in Base).cpp
73 lines (54 loc) · 1.13 KB
/
2VirtualDtor(in Base).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
73
/******************************************************************************
Example of Base, Derived : public Base, no virtual
*******************************************************************************/
/******************************************************************************
Results:
Start:
Base Ctor
Derived Ctor
Derived Ctor
Base Dtor
*******************************************************************************/
#include <iostream>
using namespace std;
class Base
{
public:
int m_i;
Base()
{
cout<<"Base Ctor"<<endl;
}
~Base()
{
cout<<"Base Dtor"<<endl;
}
void printMe()
{
cout<<"Hi, Base"<<endl;
}
};
class Derived : public Base
{
public:
int m_i;
Derived()
{
cout<<"Derived Ctor"<<endl;
}
~Derived()
{
cout<<"Derived Ctor"<<endl;
}
void printMe()
{
cout<<"Hi, Derived"<<endl;
}
};
int main()
{
cout<<"Start:"<<endl;
Base *b = new Derived;
delete b;
return 0;
}