#include<iostream>
using namespace std;
class Case;
class State{
public:
virtual void Turn(Case * pCase){}
};
class StateA :public State{
void Turn(Case * pCase){cout << "春--" ; pCase->pState = new StateB;}
};
class StateB :public State{
void Turn(Case * pCase) {cout << "夏--" ; pCase->pState = new StateC;}
};
class StateC :public State{
void Turn(Case * pCase) {cout << "秋--" ; pCase->pState = new StateD;}
};
class StateD :public State{
void Turn(Case * pCase) {cout << "冬--" ; pCase->pState = new StateA;}
};
class Case {
public:
State * pState;
Case(State *p){pState = p;}
void Run(){pState->Turn(this);}
};
void main(){
Case *p = new Case(new StateA);
for(int i=0;i<9;i++)
p->Run();
}
如何能让这个运行起来
构造函数要加括号
Case *p = new Case(new StateA());