建设银行网站定酒店,网站关联页面如何做,漳州微网站建设,网页设计与制作服务公司注意#xff1a;先做类的声明和抽象基类的声明
抽象基类的函数方法中引入类#xff0c;具体方法在类的实现后面声明。
在抽象基类的子类的函数中可以调用类的成员函数。
#include iostreamusing namespace std;class Contex;class state {
public:virtual void Ha… 注意先做类的声明和抽象基类的声明
抽象基类的函数方法中引入类具体方法在类的实现后面声明。
在抽象基类的子类的函数中可以调用类的成员函数。
#include iostreamusing namespace std;class Contex;class state {
public:virtual void Handel( Contex* contex) 0;
};class Contex {
public:Contex(state* _state) :State(_state) {};void changeState( state* _state){State _state;}void showState(){if (State ! nullptr){State-Handel(this);}}void showNum(){cout num endl;}
private:state *State nullptr;int num 10;};class state1 :public state {
public:void Handel(Contex* contex) {cout 状态1 endl;}
};class state2 :public state {
public:void Handel(Contex* contex) {cout 状态2 endl;}
};class state3 :public state {
public:void Handel(Contex* contex) {cout 状态3 endl;contex-showNum();}
};int main()
{state *myState1 new state1();state *myState2 new state2();Contex *contex new Contex(myState1);contex-showState();contex-changeState(myState2);contex-showState();state* myState3 new state3();contex-changeState(myState3);contex-showState();return 0;
}