Compiler Error Driving Me Mad


PokeParadox

Founder of Pirate Games - Penjin Coder
Staff member
Joined
Dec 8, 2005
Messages
6,603
Age
41
Location
UK
Website
pokeparadox.itch.io
WEBSITE
https://github.com/pokeparadox
YOUTUBE
pokeparadox
I am getting this error:

StateTitle.h:9: error: expected class-name before '{' token
:: === Build finished: 1 errors, 0 warnings ===

The code below is what relates to... anyone have an idea... I can't see what's wrong personally :S
CODE

#ifndef STATETITLE_H_INCLUDED
#define STATETITLE_H_INCLUDED

#include "BaseState.h"
/*
Title screen state to show title screen demo
*/
class StateTitle : public BaseState
{
public:
StateTitle();
virtual void init();
virtual void render(SDL_Surface *screen);
virtual void update();
virtual void keyboard();
virtual ~StateTitle();
};

#endif // STATETITLE_H_INCLUDED
 
Seems like BaseState is not recognised as a class by the compiler.
Be sure that the include is correct and that BaseState is correctly defined there.

Try posting BaseState.h here if you still have the problem.
 
Thanks Ryo, I can't spot anything obviously wrong in BaseState.h myself either.

CODE

#ifndef BASESTATE_H_INCLUDED
#define BASESTATE_H_INCLUDED

#include "SDL.h"
#include "States.h" // List of states that we can change to.
#include "InputHandler.h" // Keyboard handler

class BaseState
{
public:
BaseState();
virtual ~BaseState();

// These vitual functions will be overidden depending on use
virtual void render(SDL_Surface *screen);
virtual void update();
virtual void keyboard();
virtual void init(); // init function for states


inline bool getNullifyState()
{
return nullify;
}

protected:
inline void nullifyState()
{
nullify = true;
}

InputHandler input;
bool nullify;
};
#endif // BASESTATE_H_INCLUDED
 
I can't see any obvious error either, the only thing I am noticing is your use of the inline functions.

They are probably safe as they are but it's a better practice to use them as shown below:

1. Code specified in the class body but WITHOUT the inline keyword (it will still be inlined)
CODE

#ifndef BASESTATE_H_INCLUDED
#define BASESTATE_H_INCLUDED

#include "SDL.h"
#include "States.h" // List of states that we can change to.
#include "InputHandler.h" // Keyboard handler

class BaseState
{
public:
BaseState();
virtual ~BaseState();

// These vitual functions will be overidden depending on use
virtual void render(SDL_Surface *screen);
virtual void update();
virtual void keyboard();
virtual void init(); // init function for states


bool getNullifyState()
{
return nullify;
}

protected:
void nullifyState()
{
nullify = true;
}

InputHandler input;
bool nullify;
};
#endif // BASESTATE_H_INCLUDED



2. Code in the header but OUTSIDE the class body with inline keyword on the implementation:
CODE

#ifndef BASESTATE_H_INCLUDED
#define BASESTATE_H_INCLUDED

#include "SDL.h"
#include "States.h" // List of states that we can change to.
#include "InputHandler.h" // Keyboard handler

class BaseState
{
public:
BaseState();
virtual ~BaseState();

// These vitual functions will be overidden depending on use
virtual void render(SDL_Surface *screen);
virtual void update();
virtual void keyboard();
virtual void init(); // init function for states


bool getNullifyState();

protected:
void nullifyState();

InputHandler input;
bool nullify;
};

inline bool BaseState::getNullifyState()
{
return nullify;
}

inline void BaseState::nullifyState()
{
nullify = true;
}
#endif // BASESTATE_H_INCLUDED



But it's probably not this that causes your error...
If I notice something else I'll post again.
 
Thanks guys, it's appreciated. Thanks for the tip about inlining Ryo.
I can't see anything out of place in InnputHandler.h Parkydr.

EDIT: tidying up the inline keywords didn't help anything... I really can't fathom what's wrong :S
EDIT: I managed to fix the problem. I finally discovered the problem was in States.h... I think it was basically cyclic inclusions... but changing what included what sifted out the problem.
 
Back
Top