Inheritance Problem, Forward Class Declaration Not Helping

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
iam13013
Posts: 31
Joined: Sun Dec 04, 2005 11:06 pm

Inheritance Problem, Forward Class Declaration Not Helping

Post 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
CuteAlien
Admin
Posts: 9693
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post 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).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Murcho
Posts: 26
Joined: Mon Nov 10, 2008 8:45 am
Location: Australia

Post 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.
iam13013
Posts: 31
Joined: Sun Dec 04, 2005 11:06 pm

Post 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!
Post Reply