現在 Stateパターンを参考にし、下のソースを書き、コンパイルするのですが
C:\Documents and Settings\++++++++++\デスクトップ\DxLib_骨組み Stateパターン\main.cpp(134) : error C2653: 'GameStage' : 識別子がクラス名でも名前空間名でもありません。
C:\Documents and Settings\++++++++++\デスクトップ\DxLib_骨組み Stateパターン\main.cpp(136) : error C2653: 'GameStrategy' : 識別子がクラス名でも名前空間名でもありません。
C:\Documents and Settings\+++++++++++\デスクトップ\DxLib_骨組み Stateパターン\main.cpp(161) : error C2653: 'GameStrategy' : 識別子がクラス名でも名前空間名でもありません。
とコンパイルエラーがでてしまいます
コンパイルの順番で、型が定義されていないのはわかっていますが
いまのソースコードの順番を入れ替えても、また同じ型が定義されていないと
コンパイルエラーがおきてしまいそうです
これはどのようにすればコンパイルが通るようになるのでしょうか?
//==================================================================
class GameConnection;
class GameState
{
public:
virtual void Draw( GameConnection *t );
virtual void GoTitle( GameConnection *t );
virtual void GoStage( GameConnection *t );
virtual void GoStrategy( GameConnection *t );
virtual void ChangeState( GameConnection*, GameState* );
};
class GameConnection
{
GameState *_state;
public:
GameConnection( GameState * );
void UpDate();
void ChangeState( GameState *s );
};
GameConnection::GameConnection( GameState *s )
{
_state = s;
}
void GameConnection::ChangeState( GameState *s )
{
_state = s;
}
void GameConnection::UpDate()
{
_state->Draw( this );
}
//==================================================================
void GameState::ChangeState( GameConnection *t, GameState *s )
{
}
void GameState::GoTitle( GameConnection *t )
{
}
void GameState::GoStage( GameConnection *t )
{
}
void GameState::GoStrategy( GameConnection *t )
{
}
void GameState::Draw( GameConnection *t )
{
}
//==================================================================
class GameTitle : public GameState
{
static GameState *_instance;
public:
void Draw( GameConnection *t );
void GoStage( GameConnection *t );
void GoStrategy( GameConnection *t );
static GameState* GetInstance() {
if( _instance == 0 ){
_instance = new GameTitle();
}
return _instance;
}
};
GameState* GameTitle::_instance;
void GameTitle::Draw( GameConnection *t )
{
DrawString( 0, 100, "GameTitle", GetColor(255,255,2555) );
static int a;
a++;
if( a==100 )
t->ChangeState( GameStage::GetInstance() ); // コンパイルエラー GameStage が認識できない
if( a==200 )
t->ChangeState( GameStrategy::GetInstance() ); // コンパイルエラー GameStrategyが認識できない
}
void GameTitle::GoStage( GameConnection *t )
{
}
void GameTitle::GoStrategy( GameConnection *t )
{
}
//==================================================================
class GameStage : public GameState
{
static GameState *_instance;
public:
void GoTitle();
void GoStrategy( GameConnection *t );
static GameState* GetInstance() {
if( _instance == 0 ){
_instance = new GameStage();
}
return _instance;
}
};
GameState* GameStage::_instance;
void GameStage::GoStrategy( GameConnection *t )
{
t->ChangeState( GameStrategy::GetInstance() );
}
//==================================================================
class GameStrategy : public GameState
{
static GameState *_instance;
public:
void GoTitle();
void GoStage();
static GameState* GetInstance() {
if( _instance == 0 ){
_instance = new GameStrategy();
}
return _instance;
}
};
GameState* GameStrategy::_instance;
static GameConnection *connection;
//==================================================================
void func2()
{
static int c = 0;
if( c == 0 )
{
connection = new GameConnection( GameTitle::GetInstance() );
c = 1;
}
connection->UpDate();
}