/learn/test/virtual.destructor.cc
C++ | 61 lines | 34 code | 11 blank | 16 comment | 0 complexity | 58a48b90fe6fb1cdc32139c01a1d8de8 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0
- /*
- *--------------------------------------------------------------------------
- * File Name: virtual.destructor.cc
- *
- * Author: Zhao Yanbai [zhaoyanbai@126.com]
- * Sat Aug 27 14:17:13 2011
- *
- * Description: ??????????????virtual???????
- *
- *--------------------------------------------------------------------------
- */
- #include <iostream>
- using namespace std;
- class Base {
- public:
- Base() {cout<<"Base Constructor"<<endl;}
- ~Base() {cout<<"Base Deconstructor"<<endl;}
- };
- class Derived : public Base {
- public:
- Derived() {cout<<"Derived Constructor"<<endl;}
- ~Derived() {cout<<"Derived Deconstructor"<<endl;}
- };
- class VBase {
- public:
- VBase() {cout<<"VBase Constructor"<<endl;}
- virtual ~VBase() {cout<<"VBase Deconstructor"<<endl;}
- };
- class VDerived : public VBase {
- public:
- VDerived() {cout<<"VDerived Constructor"<<endl;}
- ~VDerived() {cout<<"VDerived Deconstructor"<<endl;}
- };
- int main() {
- // ???????????????????????
- // ??????????????
- cout<<"======================================="<<endl;
- Base *a = new Derived;
- delete a;
- // ????????????????????????
- cout<<"======================================="<<endl;
- Derived *b = new Derived;
- delete b;
- // ???????????????????????
- // ????,???????????????
- cout<<"======================================="<<endl;
- VDerived *c = new VDerived;
- delete c;
- return 0;
- }