sub class的析构 c++

来源:互联网 发布:中国出口东盟数据 编辑:程序博客网 时间:2024/05/21 08:48
#include <iostream>


using namespace std;


class Base{
public:
        Base(){cout << "In Base Constructure\n";}
        virtual ~Base(){cout << "In Base Deconstructure\n";}
//      ~Base(){cout << "In Base Deconstructure\n";}
};


class Child: public Base{
public:
        Child(){cout << "In Child Constructure\n";}
        ~Child(){cout << "In Child Deconstructure\n";}
};


int main()
{
        Base * b =  new Child;
        delete b;
        return 0;

}

=================================================================================

In Base Constructure
In Child Constructure
In Child Deconstructure
In Base Deconstructure

原创粉丝点击