第13周 《C++语言基础》程序阅读——多态性与抽象类 (2)
2015-05-27 09:15
375 查看
1、阅读下面的程序,并写出运行结果
(2)虚析构函数
预计运行结果:XY
实际运行结果:
(2)虚析构函数
#include <iostream> using namespace std; class BASE { private: char c; public: BASE(char n):c(n) {} virtual ~BASE() { cout<<c; } }; class DERIVED:public BASE { private: char c; public: DERIVED(char n):BASE(n+1),c(n) {} ~DERIVED(){ cout<<c; } }; int main(){ DERIVED d('X'); return 0; }
预计运行结果:XY
实际运行结果:
相关文章推荐
- 第13周 《C++语言基础》程序阅读——多态性与抽象类 (3)
- 第13周 《C++语言基础》程序阅读——多态性与抽象类 (4)
- 第13周 《C++语言基础》程序阅读——多态性与抽象类 (1)
- 《C++语言基础》程序阅读——多态性与抽象类
- 第12周-程序阅读-多态性与抽象类-虚析构函数
- 第12周-程序阅读-多态性与抽象类-纯虚函数
- 第13周-多态性--项目0-课后实践·阅读程序2.
- 第13周-多态性-项目0-课后实践·阅读程序1.
- 第13周多态性与虚函数程序阅读
- 第12周-程序阅读-多态性与抽象类-虚函数
- 第13周项目训练1.2 阅读程序
- 第13周项目 程序阅读(4)
- 第14周 《C++语言基础》程序阅读——标准输入输出对象及文本文件 (3)(2)
- 第13周实验报告1 :虚函数、多态性和抽象类的理解
- 第13周 阅读程序,写出运行结果。(1)虚函数
- 《C++语言基础》程序阅读——二进制文件及文件的随机读写(4)
- 第13周 阅读程序,写出运行结果。 2.(2)交通工具类之虚函数
- 14周阅读程序1.(1)(了解多态性)
- 第13周程序阅读(2)
- 第12周 《C++语言基础》程序阅读——多重继承(1)