Hi,
I want to implement a statemachine using an array of member function pointers instead of using switch-case statements:
This is the original situation:
I want to change the HandleState function to something like this:Code:class MyClass { private: UCHAR m_ucState; public: BOOL HandleState(); BOOL HandleState_1(); BOOL HandleState_2(); BOOL HandleState_3(); } BOOL MyClass::HandleState() { switch(m_ucState) { case 1: return HandleState_1(); case 2: return HandleState_2(); case 3: return HandleState_3(); } }
Can anyone help me how I should declare the 'm_myStateHandlers' array? I should be a membervariable and all HandleState_... functions are not static.Code:BOOL MyClass::HandleState() { return m_myStateHandlers[m_ucState](); }
Thanks in advance,
Ward



LinkBack URL
About LinkBacks


