虚析构函数的必要性
2017-05-02 21:55
106 查看
#include"iostream"
using namespace std;
class base1{
public:
base1(){
cout << "父类构造函数" << endl;
}
~base1(){
cout << "父类的析构函数" << endl;
}
virtual void print(){
cout << "virtual base1.print();" << endl;
}
};
class derived1 :public base1{
int b;
public:
derived1(){
cout << "子类构造函数" << endl;
}
~derived1(){
cout << "子类的析构函数" << endl;
}
virtual void print(int a = 0){
cout << "virtual derived.print();" << endl;
}
};
void f(){
base1 *d=new derived1;
delete d;
}
int main(){
f();
system("pause");
return 0;
}
using namespace std;
class base1{
public:
base1(){
cout << "父类构造函数" << endl;
}
~base1(){
cout << "父类的析构函数" << endl;
}
virtual void print(){
cout << "virtual base1.print();" << endl;
}
};
class derived1 :public base1{
int b;
public:
derived1(){
cout << "子类构造函数" << endl;
}
~derived1(){
cout << "子类的析构函数" << endl;
}
virtual void print(int a = 0){
cout << "virtual derived.print();" << endl;
}
};
void f(){
base1 *d=new derived1;
delete d;
}
int main(){
f();
system("pause");
return 0;
}
相关文章推荐
- 网络漏洞扫描系统的必要性
- 企业内软件资产管理的必要性
- 模式分析和基于Python的DSLs的必要性
- 虚析构函数
- [SOA征文]从业务驱动看业务端标准化的必要性 推荐
- C++中的虚析构函数
- 过程分解的必要性
- c++继续学习 virtual Destruct function (虚析构函数)
- 冗余的必要性(给初学者)
- 基类的虚析构函数
- 《ERP从内部集成起步》读书笔记——第2章 从优化业务流程谈信息集成的必要性 2.2信息集成与实时共享2.2.3知情与知用
- 数组中非数字键名加引号的必要性
- 虚析构函数
- 对ERP系统进行数据安检的必要性
- 从JSP数据库的连接看J2EE服务器和连接池的必要性
- C++虚析构函数
- 个人对继承理解以及虚析构函数的理解
- 虚析构函数的作用
- 代码Review的必要性和考虑要素 .
- 虚析构函数(√)、纯虚析构函数(√)、虚构造函数(X)