您的位置:首页 > 编程语言 > C语言/C++

第13周 《C++语言基础》程序阅读——多态性与抽象类 (2)

2015-05-27 09:15 375 查看
1、阅读下面的程序,并写出运行结果

(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

实际运行结果:



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: