标签:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include<iostream> using namespace std; class ClxBase{ public : ClxBase() {}; ~ClxBase() {cout << "Output from the destructor of class ClxBase!" << endl;}; void DoSomething() { cout << "Do something in class ClxBase!" << endl; }; }; class ClxDerived : public ClxBase{ public : ClxDerived() {}; ~ClxDerived() { cout << "Output from the destructor of class ClxDerived!" << endl; }; void DoSomething() { cout << "Do something in class ClxDerived!" << endl; }; }; int main(){ ClxBase *p = new ClxDerived; //基类指针,指向派生类 p->DoSomething(); delete p; //这里因为析构函数不是虚函数,所以仅仅调用基类 的 析构函数 return 0; } |
标签:
原文地址:http://www.cnblogs.com/zhxshseu/p/5292941.html