首页 > 其他 > 详细

多态 C2

时间:2015-03-27 22:03:46      阅读:277      评论:0      收藏:0      [点我收藏+]
  
class apple {
public:
  ~apple(){ std::cout << "~apple()" << std::endl;}
};

class banana : public apple {
  ~banana(){ std::cout << "~banana()" << std::endl;}
};

class cat {
  virtual ~cat(){ std::cout << "~cat()" << std::endl;}
}; 

class dog : public cat {
  ~dog(){ std::cout << "~dog" << std::endl;}
};

int main(void)
{
  banana* pa1 = new banana;
  delete pa1;

  banana* pa2 = new banana;
  delete (apple*)pa2;

  dog* pd1 = new dog;
  delete pd1;

  dog* pd2 = new dog;
  delete (cat*)dog;  
}

 

  

多态 C2

原文:http://www.cnblogs.com/dotdog/p/4372935.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!