代码拉取完成,页面将自动刷新
//策略模式 {将功能分类}
#include<iostream>
using namespace std;
class Takeoff{//飞机的起飞方式基类
public:
virtual void takeoff()=0;
virtual ~Takeoff(){}
};
class Reritied:public Takeoff{
public:
void takeoff(){
cout<<"Reritied"<<endl;
}
};
class LongDictance:public Takeoff{
public:
void takeoff(){
cout<<"LongDictance"<<endl;
}
};
class FlyBelanchir{//飞机的速度基类
public:
virtual void fly()=0;
virtual ~FlyBelanchir(){}
};
class SubSonic:public FlyBelanchir{
public:
void fly(){
cout<<"Subsonic"<<endl;
}
};
class Sup:public FlyBelanchir{
public:
void fly(){
cout<<"Sup"<<endl;
}
};
class Plan{//飞机
protected:
Takeoff * t;
FlyBelanchir * f;
public:
Plan(Takeoff * t,FlyBelanchir * f){
this->t=t;
this->f=f;
}
virtual void takeoff()=0;
virtual void fly()=0;
virtual ~Plan(){
delete t;
delete f;
}
};
class Helicoptor:public Plan{
public:
Helicoptor(Takeoff * t,FlyBelanchir * f):Plan(t,f){}
void takeoff(){
t->takeoff();
}
void fly(){
f->fly();
}
};
class Airplane:public Plan{
public:
Airplane(Takeoff * t,FlyBelanchir * f):Plan(t,f){}
void takeoff(){
t->takeoff();
}
void fly(){
f->fly();
}
};
class Fighter:public Plan{
public:
Fighter(Takeoff * t,FlyBelanchir * f):Plan(t,f){}
void takeoff(){
t->takeoff();
}
void fly(){
f->fly();
}
};
int main(void)
{
Plan * f=new Fighter(new Reritied(),new Sup());
f->takeoff();
f->fly();
delete f;
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。