forked from Light-City/CPlusPlusThings
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfull_virde.cpp
More file actions
39 lines (35 loc) · 765 Bytes
/
full_virde.cpp
File metadata and controls
39 lines (35 loc) · 765 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
/**
* @file full_virde.cpp
* @brief 将基类的析构函数声明为虚函数
* 输出结果:
* Constructing base
* Constructing derived
* Destructing derived
* Destructing base
* @author 光城
* @version v1
* @date 2019-07-24
*/
#include<iostream>
using namespace std;
class base {
public:
base()
{ cout<<"Constructing base \n"; }
virtual ~base()
{ cout<<"Destructing base \n"; }
};
class derived: public base {
public:
derived()
{ cout<<"Constructing derived \n"; }
~derived()
{ cout<<"Destructing derived \n"; }
};
int main(void)
{
derived *d = new derived();
base *b = d;
delete b;
return 0;
}