Page 1 of 1

Inheritance Problem, Forward Class Declaration Not Helping

Posted: Wed Nov 26, 2008 1:26 am
by iam13013
I'm trying to implement an FSM of sorts, and I'm getting this error,
cmainmenu.h( 18 ) : error C2504: 'cGameState' : base class undefined
with this code:

cGameState.h

Code: Select all

class cGameState
{
yada yada yada.....
};
cGameState.cpp

Code: Select all

#include "cGameState.h"

void cGameState::yada yada yada.....
cMainMenu.h

Code: Select all

#include "cGameState.h"

class cMainMenu : public cGameState
{
yada yada yada.....
};
cMainMenu.cpp

Code: Select all

#include "cMainMenu.h"

void cMainMenu::yada yada yada.....
I wrote it, it wasn't working, so I tried a Forward Class Declaration.
cMainMenu.h

Code: Select all

class cGameState;

class cMainMenu : public cGameState
{
............
};
and I still get the same error. I realize that it is probably just some silly
little something I'm missing, but I need help... PLEASE....

Thanks in advance

Posted: Wed Nov 26, 2008 1:33 am
by CuteAlien
Is that the line (line 18) where you get the error?

Code: Select all

class cMainMenu : public cGameState 
Then the error is rather self-explaining. The baseclass is not defined (forward declarations don't do that). So you need to include cGameState.h before that.

edit: ups - you do that. OK, then it doesn't include it for some reasons. Either you have no header guards (google for it) or a circular reference in the includes (cGameState.h includes cMainMenu.h).

Posted: Wed Nov 26, 2008 1:37 am
by Murcho
Vitek posted up some really good state machine/graph code for me a couple of days ago in this thread. I've used it to setup my project and it works really well. Just thought it might save you some time.

Posted: Wed Nov 26, 2008 1:51 am
by iam13013
CuteAlien wrote:...or a circular reference in the includes...
That was it...I guess...
For some reason I was including cGame.h (which included cMainMenu.h) in cGameState.h, so I took it out and....Problem Solved!

Thanks!