Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Base class undefined compiler error  (Read 2446 times)

0 Members and 1 Guest are viewing this topic.

bucknasty189

  • Newbie
  • *
  • Posts: 23
    • View Profile
Base class undefined compiler error
« on: April 08, 2011, 01:28:52 am »
My game runs fine with one state defined and used. However, when I add a second state's header and cpp into my project, without even using it,
I get error C2504: base class undefined.

Code: [Select]


#ifndef GAMESTATE_H_
#define GAMESTATE_H_

#include "cGameEngine.h"

namespace DE
{
class cGameEngine; //<-tried comment out, still doesn't work
class cGameState
{
public:

virtual void Show() = 0;
virtual void Hide() = 0;
virtual void Pause() = 0;
virtual void Resume() = 0;

virtual void HandleEvents(sf::Event* theEvent) = 0;
virtual void Update() = 0;
virtual void Draw() = 0;

protected:
// cGameState constructor
cGameState(cGameEngine* game) :
m_Game(game),
m_Show(true)
{}

// Pointer to hold the game
cGameEngine* m_Game;

// bool to determine whether to show or hide the state
bool m_Show;

}; // class cGamestate
} // namespace DE

#endif //GAMESTATE_H_


I have forward declarations of all my classes in a types header file which is included into my cGameEngine class header. Could this have anything to do with it?

Here is where the compiler is saying the error is
Code: [Select]

#ifndef SPLASH_SCREEN_H
#define SPLASH_SCREEN_H

#include "cGameState.h"

namespace DE
{
class SplashState : public cGameState
{
public:

SplashState(cGameEngine* game);

~SplashState();

void Show();
void Hide();

void Pause();
void Resume();

void HandleEvents(sf::Event* theEvent);
void Update();
void Draw();

/* static SplashState* Instance()
{
return &m_SplashState;
}
*/
protected:
// SplashState(){}

private:
// static SplashState m_SplashState;
sf::Sprite* m_Player;
sf::Sprite* m_BackGround;
cp::cpButton m_StartButton;


}; // class SplashState
} // namespace DE
#endif // SPLASH_SCREEN_H
Knowledge Speaks,
Wisdom Listens
                       -JH

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Base class undefined compiler error
« Reply #1 on: April 08, 2011, 10:38:20 am »
When you inherit a class, the base class must be a complete type, that is its definition must be visible. A forward declaration leaves the type incomplete.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

bucknasty189

  • Newbie
  • *
  • Posts: 23
    • View Profile
Base class undefined compiler error
« Reply #2 on: April 08, 2011, 11:39:16 pm »
I figured it had something to do with the forward declares.  I had my cGameState being forward declared in the cGameEngine class. Just switched it and forward declared the cGameEngine in the cGameState and it worked beautifully.

Thanks for your help once again Nexus!
Knowledge Speaks,
Wisdom Listens
                       -JH