http://www.play21.jp/board/formz.cgi?ac ... &rln=54610
の続きですが
Stage2を追加し、コンパイルしようとしたらコンパイルエラーになってしまって先に進めません
コンパイルの内容です
---------------------------------------------------------------------------------------------
コンパイル中...
main.cpp
C:\Documents and Settings\デスクトップ\state\main.cpp(48) : error C2027: 認識できない型 'Stage2' が使われています。
C:\Documents and Settings\デスクトップ\state\main.cpp(29) : 'Stage2' の宣言を確認してください。
cl.exe の実行エラー
---------------------------------------------------------------------------------------------
以下がソースです
#include <iostream> class Connection { }; //-------------------------------------------------------- class State { protected: void ChangeState( Connection*, State* ); public: virtual void A( Connection* ); virtual void B( Connection* ); virtual void C( Connection* ); virtual void D( Connection* ); }; void State::ChangeState( Connection *t, State *s ) { printf( "State::ChangeState\n" ); } void State::A( Connection* ) { printf( "State::A\n" ); } //-------------------------------------------------------- class Stage1; class Stage2; //-------------------------------------------------------- class Stage1 : public State { public: static State* _instance; static State* Instance() { if( _instance == 0 ) _instance = new Stage1; return _instance; } void A( Connection* ); void B( Connection* ); }; State* Stage1::_instance = 0; void Stage1::A( Connection* t ) { printf( "Stage1::A\n" ); ChangeState( t, Stage2::Instance() ); } void Stage1::B( Connection* t ) { } //-------------------------------------------------------- class Stage2 : public State { public: static State* _instance; static State* Instance() { if( _instance == 0 ) _instance = new Stage2; return _instance; } void C( Connection* ); void D( Connection* ); }; void Stage2::C( Connection* t ) { printf( "Stage2::C\n" ); ChangeState( t, Stage1::Instance() ); } void Stage2::D( Connection* ) { } //-------------------------------------------------------- int main() { State *stage1 = new Stage1; Connection *connection = new Connection; stage1->A( connection ); return 0; }---------------------------------------------------------------------------------------------
Stage2をStage1からコンパイルしようできず
また
Stage1からStage2をコンパイルできない状態です
どのようにして、この関係を解決することができるでしょうか?