第十三周——虚析构函数

来源:互联网 发布:中国社会发展数据库 编辑:程序博客网 时间:2024/06/07 10:34
  1. *Copyright (c) 2015,烟台大学计算机学院 
  2. *All rights reserved. 
  3. *文件名称:text.cpp 
  4. *作者:李德彪
  5. *完成日期:2015年5月25日 
  6. *版本号:v1.0 
  7. * 
  8. *问题描述:  阅读程序,写出运行结果 
  9. *输入描述: 无 
  10. *程序输出:  测试结果 
  11. */  
  12. #include <iostream>  
  13.   
  14. using namespace std;  
  15. class BASE  
  16. {  
  17. private :  
  18.     char c;  
  19. public :  
  20.     BASE(char n):c(n){}  
  21.     virtual ~BASE(){cout<<c;}  
  22. };  
  23. class DERIVED:public BASE  
  24. {  
  25. private:  
  26.     char c;  
  27. public :  
  28.     DERIVED(char n):BASE(n+1),c(n){}  
  29.     ~DERIVED(){cout<<c;}  
  30. };  
  31. int main()  
  32. {  
  33.     DERIVED d('x');  
  34.     return 0;  
  35. }  
0 0
原创粉丝点击