Reputation: 17832
I have a State class that is fully implemented as outlined below. I also have a PlayState class that inherits the State class, it too is fully implemented. My compile error is "playstate.h(6): error C2504: 'State' : base class undefined" I have checked their order in Global.h, State.h appears before PlayState.h
CODE:
STATE.H
#pragma once
#include "Global.h"
class State
{
public:
State(void);
virtual ~State(void);
virtual void Input(INPUTDATA* InputData);
virtual void Logic(OBJECT go[], INPUTDATA* InputData);
virtual void Render(OBJECT go[]);
virtual void InitGame(OBJECT go[]);
virtual void LoadGraphics(void);
void Toggle();
bool IsEnabled();
private:
bool isEnabled;
};
PlayState.h
#include "Global.h"
class PlayState : public State
{
private:
#define UPDATESPEED 1000 // milliseconds between each update
// global variables
float camXAngle;
float camYAngle;
float camZoom;
int updatetime;
bool gameover;
float runspeed;
D3DLIGHT9 light;
SPRITE graphics;
SPRITE particleTexture;
MODEL terrain[2];
MODEL sky;
public:
PlayState();
~PlayState();
void Input(INPUTDATA* InputData);
void Logic(OBJECT go[], INPUTDATA* InputData);
void Render(OBJECT go[]);
void InitGame(OBJECT go[]);
void LoadGraphics(void);
};
Thanks
Upvotes: 2
Views: 3328
Reputation: 17832
#pragma once
#include "Global.h"
class PlayState : public State
What is "State"? That is what the compiler is complaining about.
You can't inherit from a class that has not been fully defined. Looking at the file PlayState.h, nowhere do you specify the State class.
CORRECTED CODE:
#pragma once
#include "State.h"
class PlayState : public State
Upvotes: 0
Reputation: 4429
If some *.cpp includes "State.h" without "Global.h" somewhere before it then you will have the error that you've posted.
Because when "State.h" includes "Global.h" then "Global.h" does not include "State.h" (because of #pragma once
) but it includes "PlayState.h" so in the end you have "PlayState.h" included before class State
is defined.
Just don't make such weird circular inclusions.
Upvotes: 4
Reputation: 206498
If your Global.h
already includes State.h
and PlayState.h
and in the order that State.h
is placed before PlayState.h
, then there is no reason to get the particular error(for the source code you have posted), unless except you are making some silly typo like missing a caps in State. Please check for typos! or there might be another reason to the problem.
You are building a circular dependency of includes, which should be avoided.
A simple solution might be to not include both includes, State.h
and PlayState.h
in Global.h
.
Just include State.h
inside PlayState.h
and it should be fine. Global.h
wont build up any circular dependencies that way.
Upvotes: 1