Ok dose every one remember this article http://www.cprogramming.com/tutorial/gamedesign.html
I have made a few engines with the old school style and i like this approach better. But there is one thing i am having problems with.
Ok the article stipulates that Execute() member function returns a pointer to a Module, which is the next Module. This all make nice since because the next Module will have the Module base class and we are only concerned with accessing the functions that the Module pointer can see. But the returned Module is a pointer to the next Module, So do i just make however many Module pointer slots i need in the derived class and in the Initialize member function assign all of them to a bunch of pre-made instances of Pointers to Modules that are assigned to a 'new' derived class instance? This is exactly what i did but the classes are having trouble seeing those instances. Am i going about this all wrong or what? Thanks for the help
This is confusing to explain so here is the Test code that is not working
Code:#include <iostream> using namespace std; class Module { public: virtual void Initialize()=0; virtual Module* Execute()=0; virtual void Shutdown()=0; } class Test : public Module { protected: int number; char word; Module* NextModule; public: //general methods void Initialize(); Module* Execute(); void Shutdown(); Test(); ~Test(); //accessor methods int GetNumber() {return number;}; char GetChar() {return word;}; } class TestB : public Module { protected: int number; char word; Module* NextModule; public: //general methods void Initialize(); Module* Execute(); void Shutdown(); TestB(); ~TestB(); //accessor methods int GetNumber() {return number;}; char GetChar() {return word;}; } Module* pTestB = new TestB; Module* pTest = new Test; Module* CurrentModule; Module* LastModule; main() { int end = 0; CurrentModule = pTest; LastModule = CurrentModule; while(end == 0) { if((CurrentModule=CurrentModule->Initialize()) != LastModule) { cout<<"inside if"<<endl; LastModule->Shutdown(); CurrentModule->Initialize(); cout<<"Would You Like to Quit? " <<endl; cin>>endl; } if(end == 0) { cout<<"Inside Second If" <<endl; cout<<"Would You Like to Quit? " <<endl; cin>>end; } delete Test; delete pTestB; } } void Test::Initialize() { number = 1; word = 'F'; NextModule = pTestB; Execute(); } Module* Test::Execute() { cout <<number <<endl; cout <<word <<endl; return NextModule; } void Test::Shutdown() { number = 20; word = 'D'; cout <<number <<endl; cout <<word <<endl; } void TestB::Initialize() { number = 500; word = 'S'; NextModule = pTest; Execute(); } Module* TestB::Execute() { cout <<number <<endl; cout <<word <<endl; return NextModule; } void TestB::Shutdown() { number = 20; word = 'D'; cout <<number <<endl; cout <<word <<endl; }