现在的位置: 首页 > 综合 > 正文

多重继承

2018年04月14日 ⁄ 综合 ⁄ 共 622字 ⁄ 字号 评论关闭

#include <iostream>
using namespace std;
class father
{
public:
 void smart(){cout<<"父亲很聪明!"<<endl;}
 virtual void beautiful(){}
 virtual ~father(){cout<<"析构父亲类!"<<endl;}
};
class son:public father
{
public:
 void beautiful(){cout<<"儿子也很英俊!"<<endl;}
 ~son(){cout<<"析构儿子类!"<<endl;}
};
int main()
{
 father*pf;
 int choice=0;
while(choice<99)
{
 bool quit=false;
 cout<<"[0]退出[1]父亲[2]儿子:";
 cin>>choice;
 switch (choice)
 {
 case 0:
  quit=true;
  break;
 case 1:
  pf=new father;
  pf->beautiful();
  break;
 case 2:
  pf=new son;
  pf->beautiful();
  pf->smart();
  delete pf;
  break;
 default:cout<<"请输入从0到2之前的数"<<endl;
 }
 if (quit==true)
 {
  break;
 }
}
 cout<<"程序结束!"<<endl;
 return 0;
}

抱歉!评论已关闭.