PageRenderTime 135ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/learn/test/virtual.destructor.cc

http://puppycodes.googlecode.com/
C++ | 61 lines | 34 code | 11 blank | 16 comment | 0 complexity | 58a48b90fe6fb1cdc32139c01a1d8de8 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0
  1. /*
  2. *--------------------------------------------------------------------------
  3. * File Name: virtual.destructor.cc
  4. *
  5. * Author: Zhao Yanbai [zhaoyanbai@126.com]
  6. * Sat Aug 27 14:17:13 2011
  7. *
  8. * Description: ??????????????virtual???????
  9. *
  10. *--------------------------------------------------------------------------
  11. */
  12. #include <iostream>
  13. using namespace std;
  14. class Base {
  15. public:
  16. Base() {cout<<"Base Constructor"<<endl;}
  17. ~Base() {cout<<"Base Deconstructor"<<endl;}
  18. };
  19. class Derived : public Base {
  20. public:
  21. Derived() {cout<<"Derived Constructor"<<endl;}
  22. ~Derived() {cout<<"Derived Deconstructor"<<endl;}
  23. };
  24. class VBase {
  25. public:
  26. VBase() {cout<<"VBase Constructor"<<endl;}
  27. virtual ~VBase() {cout<<"VBase Deconstructor"<<endl;}
  28. };
  29. class VDerived : public VBase {
  30. public:
  31. VDerived() {cout<<"VDerived Constructor"<<endl;}
  32. ~VDerived() {cout<<"VDerived Deconstructor"<<endl;}
  33. };
  34. int main() {
  35. // ???????????????????????
  36. // ??????????????
  37. cout<<"======================================="<<endl;
  38. Base *a = new Derived;
  39. delete a;
  40. // ????????????????????????
  41. cout<<"======================================="<<endl;
  42. Derived *b = new Derived;
  43. delete b;
  44. // ???????????????????????
  45. // ????,???????????????
  46. cout<<"======================================="<<endl;
  47. VDerived *c = new VDerived;
  48. delete c;
  49. return 0;
  50. }