template<class xUsers_states>
class CStates
{
CStates(void);
public:
//BEGIN STATE:
//take message from previus state
//to see if transisation is possible
// return 1 for success, 0 for fail
virtual FAST_BOOL Enter(xUsers_states*)=0;
//EXECUTE OUR STATE:
//Now lets get things rolling
virtualvoid Execute(xUsers_states*)=0;
//EXITING STATE:
//Pass message to our successor
//return our address to let the successor know,
//this message affects the call of action of our successor
virtual CStates<xUsers_states>* Exit(xUsers_states*)=0;
//virtual destructors are needed for pure virtual classes
//its children will handle differently
virtual ~CStates(void);
};
Here: my attempt to inherite it, the issue here is that it refuses to achknowledge my "CGAME_MANAGER" even though I've inherited it in the template through "public CStates<CGAME_MANAGER>".
class CStart_Menu :
public CStates<CGAME_MANAGER>
{
private:
CStart_Menu(void);
public:
//BEGIN STATE:
//take message from previus state
//to see if transisation is possible
// return 1 for success, 0 for fail
virtual FAST_BOOL Enter(CStates*);
//EXECUTE OUR STATE:
//Now lets get things rolling
virtualvoid Execute(CGAME_MANAGER*);
//EXITING STATE:
//Pass message to our successor
//return our address to let the successor know,
//this message affects the call of action of our successor
virtual CStates* Exit(CStates*);
//SINGLETON DECLARATION
static CStart_Menu * Instance();
virtual ~CStart_Menu(void);
};
"CGAME_MANAGER" does not define a type, so you need a template declaration for it above your definition of "CStart_Menu". I'm glad to see a user in the beginner forums using objects, good work so far.
In the future, it would really help if you posted the actual errors rather than your interpretation of what the error means.
You have 2 problems here:
1) Your Enter and Exit functions take a xUsers_states* as a parameter in the parent class, but a CState* in the child class (note this is wrong for 2 reasons: one is that they don't match, and two is that CState isn't a class -- it's a template -- so you can't have a pointer to it.)
One solution here would be to change CStart_Menu so that Enter and Exit both take CGAME_MANAGER* as a parameter.
2) CState's ctor is private, so CStart_Menu won't be able to access it (so you won't be able to derive from it). One solution is to make it protected instead of private.
But I now think I'm at the age where posting just errors may seem like code dumping, so I been trying to explain them instead. but here are the errors anyway
1>------ Build started: Project: Game state machine, Configuration: Debug Win32 ------
1>Build started 10/10/2011 14:59:59.
1>InitializeBuildStatus:
1> Touching "Debug\Game state machine.unsuccessfulbuild".
1>ClCompile:
1> game_main.cpp
1>g:\year2\game software engineering gameng\mazuma engine\game state machine\start_menu.h(11): error C2065: 'CGAME_MANAGER' : undeclared identifier
1>g:\year2\game software engineering gameng\mazuma engine\game state machine\start_menu.h(12): error C2955: 'CStates' : use of class template requires template argument list
1> g:\year2\game software engineering gameng\mazuma engine\game state machine\states.h(22) : see declaration of 'CStates'
1>g:\year2\game software engineering gameng\mazuma engine\game state machine\start_menu.h(21): error C2061: syntax error : identifier 'CGAME_MANAGER'
1>g:\year2\game software engineering gameng\mazuma engine\game state machine\start_menu.h(25): error C2061: syntax error : identifier 'CGAME_MANAGER'
1>g:\year2\game software engineering gameng\mazuma engine\game state machine\start_menu.h(31): error C2061: syntax error : identifier 'CGAME_MANAGER'
1>g:\year2\game software engineering gameng\mazuma engine\game state machine\start_menu.h(37): warning C4511: 'CStart_Menu' : copy constructor could not be generated
1> g:\year2\game software engineering gameng\mazuma engine\game state machine\start_menu.h(10) : see declaration of 'CStart_Menu'
1>g:\year2\game software engineering gameng\mazuma engine\game state machine\start_menu.h(37): warning C4512: 'CStart_Menu' : assignment operator could not be generated
1> g:\year2\game software engineering gameng\mazuma engine\game state machine\start_menu.h(10) : see declaration of 'CStart_Menu'
1> GAME_MANAGER.cpp
1>g:\year2\game software engineering gameng\mazuma engine\game state machine\start_menu.h(11): error C2065: 'CGAME_MANAGER' : undeclared identifier
1>g:\year2\game software engineering gameng\mazuma engine\game state machine\start_menu.h(12): error C2955: 'CStates' : use of class template requires template argument list
1> g:\year2\game software engineering gameng\mazuma engine\game state machine\states.h(22) : see declaration of 'CStates'
1>g:\year2\game software engineering gameng\mazuma engine\game state machine\start_menu.h(21): error C2061: syntax error : identifier 'CGAME_MANAGER'
1>g:\year2\game software engineering gameng\mazuma engine\game state machine\start_menu.h(25): error C2061: syntax error : identifier 'CGAME_MANAGER'
1>g:\year2\game software engineering gameng\mazuma engine\game state machine\start_menu.h(31): error C2061: syntax error : identifier 'CGAME_MANAGER'
1>g:\year2\game software engineering gameng\mazuma engine\game state machine\start_menu.h(37): warning C4511: 'CStart_Menu' : copy constructor could not be generated
1> g:\year2\game software engineering gameng\mazuma engine\game state machine\start_menu.h(10) : see declaration of 'CStart_Menu'
1>g:\year2\game software engineering gameng\mazuma engine\game state machine\start_menu.h(37): warning C4512: 'CStart_Menu' : assignment operator could not be generated
1> g:\year2\game software engineering gameng\mazuma engine\game state machine\start_menu.h(10) : see declaration of 'CStart_Menu'
1>g:\year2\game software engineering gameng\mazuma engine\game state machine\game_manager.cpp(9): error C2664: 'CStateMachine<qXType_state>::SetCurrentState' : cannot convert parameter 1 from 'CStart_Menu *' to 'CStates<xUsers_states> *'
1> with
1> [
1> qXType_state=CGAME_MANAGER
1> ]
1> and
1> [
1> xUsers_states=CGAME_MANAGER
1> ]
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1> Start_Menu.cpp
1>g:\year2\game software engineering gameng\mazuma engine\game state machine\statemachine.h(46): error C2664: 'CStateMachine<qXType_state>::State_Active' : cannot convert parameter 1 from 'CStates<xUsers_states> *' to 'CStates<xUsers_states> &'
1> with
1> [
1> qXType_state=CGAME_MANAGER
1> ]
1> and
1> [
1> xUsers_states=CGAME_MANAGER
1> ]
1> and
1> [
1> xUsers_states=CGAME_MANAGER
1> ]
1> g:\year2\game software engineering gameng\mazuma engine\game state machine\statemachine.h(44) : while compiling class template member function 'unsigned char CStateMachine<qXType_state>::ChangingState(CStates<xUsers_states> *)'
1> with
1> [
1> qXType_state=CGAME_MANAGER,
1> xUsers_states=CGAME_MANAGER
1> ]
1> g:\year2\game software engineering gameng\mazuma engine\game state machine\game_manager.h(41) : see reference to class template instantiation 'CStateMachine<qXType_state>' being compiled
1> with
1> [
1> qXType_state=CGAME_MANAGER
1> ]
1>g:\year2\game software engineering gameng\mazuma engine\game state machine\statemachine.h(51): error C3867: 'CStates<xUsers_states>::Exit': function call missing argument list; use '&CStates<xUsers_states>::Exit' to create a pointer to member
1> with
1> [
1> xUsers_states=CGAME_MANAGER
1> ]
1> Generating Code...
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.29
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
thanks Disch, those errors where fixed, but now I've got the using class issue:
basically, it seems to accept the declaration in the headerfile, but I can't redeclare these pure I cant redeclare them in the .cpp file or even tell them that I need them to be virtual.
externclass CGAME_MANAGER;
class CStart_Menu :
public CStates<CGAME_MANAGER>
{
private:
CStart_Menu(void);
public:
//BEGIN STATE:
//take message from previus state
//to see if transisation is possible
// return 1 for success, 0 for fail
using CStates<CGAME_MANAGER>::Enter(CGAME_MANAGER*);
//EXECUTE OUR STATE:
//Now lets get things rolling
using CStates<CGAME_MANAGER>::Execute(CGAME_MANAGER*);
//EXITING STATE:
//Pass message to our successor
//return our address to let the successor know,
//this message affects the call of action of our successor
using CStates<CGAME_MANAGER>::Exit(CGAME_MANAGER*);
//SINGLETON DECLARATION
static CStart_Menu * Instance();
virtual ~CStart_Menu(void);
};
#define stSTART_MENU CStart_Menu::Instance()
//eturn 1 for success, 0 for fail
using CStates<CGAME_MANAGER>::Enter(CGAME_MANAGER* qp_laststate)
{
//Test if there is a transisation
//from the previous state
qp_laststate->Use_StateMachine()->CurrentState();
/*
if ((qp_laststate->Use_StateMachine()->CurrentState())== (extern)knownstate)
if(!(execute trasition()))//returns true if transition complete
{return 0}//else carry on with transition
else if (try known transition number 2)
.....
else
//ADD ANIMATION:
*/
//LISTEN FOR BUTTONS (skip option here)
//transition complete
return 1;
}