您好,欢迎来到华佗养生网。
搜索
您的当前位置:首页C++多态实现机制

C++多态实现机制

来源:华佗养生网

#include <iostream.h>
class animal
{
  public:
  void sleep()
  {
    cout<<"animal sleep"<<endl;
  }
void breathe()
{
  cout<<"animal breathe"<<endl;
}
};
class fish:public animal
{
public:
  void breathe()
  {
    cout<<"fish bubble"<<endl;
  }
};
void main()
{
  fish fh;
  animal *pAn=&fh;
  pAn->breathe();
}
答案是输出:animal breathe

多态机制:

转载于:https://www.cnblogs.com/vinke2013/p/7209347.html

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo7.cn 版权所有 湘ICP备2022005869号-9

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务