设为首页 加入收藏

TOP

C++ 面试题-虚析构函数
2011-04-25 22:24:45 来源: 作者: 【 】 浏览:1294
Tags:试题 函数

程序改错
class mml
{
  private:
    static unsigned int x;
  public:
    mml(){ x++; }
    mml(static unsigned int &) {x++;}
    ~mml{x--;}
  pulic:
    virtual mon() {} = 0;
    static unsigned int mmc(){return x;}
    ......                      
 
};
class nnl:public mml
{
  private:
    static unsigned int y;
  public:
    nnl(){ x++; }
    nnl(static unsigned int &) {x++;}
    ~nnl{x--;}
  public:
    virtual mon() {};
     static unsigned int nnc(){return y;}
    ......                   
};

代码片断:
mml* pp = new nnl;
..........
delete pp;


A:
基类的析构函数应该为虚函数
virtual ~mml{x--;}

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++ 面试题-真币重还是假币重 下一篇C++ 面试题-指针传递