Dec 12, 2013 at 12:44am UTC
I am receiving the error message 'TheGame' : is not a class or namespace name.
I have included typedef Game TheGame; in the global scope of the game.h header.
1 2 3 4 5
void SDLGameObject::draw()
{
TextureManager::Instance()->drawFrame(m_textureID, m_x, m_y, m_width, m_height, m_currentRow, m_currentFrame, TheGame::Instance()->getRenderer());
};
Above is the particular set of lines which is causing trouble. TheGame::Instance()->getRenderer()
Below is the contents of the GameObject.h header.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
#ifndef __GameObject__
#define __GameObject__
#include <SDL.h>
#include <string>
#include "LoaderParams.h"
#include "TextureManager.h"
#include "game.h"
class GameObject
{
public :
virtual void draw()= 0;
virtual void update()=0;
virtual void clean()=0;
protected :
GameObject(const LoaderParams* pParams) {}
virtual ~GameObject()
{}
};
class SDLGameObject : public GameObject
{
public :
SDLGameObject(const LoaderParams* pParams);
virtual void draw();
virtual void update();
virtual void clean();
protected :
int m_x;
int m_y;
int m_width;
int m_height;
int m_currentRow;
int m_currentFrame;
std::string m_textureID;
};
SDLGameObject::SDLGameObject(const LoaderParams* pParams) :
GameObject(pParams)
{
m_x = pParams->getX();
m_y = pParams->getY();
m_width = pParams->getWidth();
m_height = pParams->getHeight();
m_textureID = pParams->getTextureID();
m_currentRow = 1;
m_currentFrame = 1;
};
void SDLGameObject::draw()
{
TextureManager::Instance()->drawFrame(m_textureID, m_x, m_y, m_width, m_height, m_currentRow, m_currentFrame, TheGame::Instance()->getRenderer());
};
#endif /*
defined (__GameObject__) */
Last edited on Dec 12, 2013 at 12:46am UTC
Dec 12, 2013 at 12:52am UTC
What is 'TheGame'? You don't have it defined anywhere. The compiler doesn't know what it is.
EDIT:
I missed your note about the typedef.
In that case, it must not be seeing the typedef. Is game.h including gameobject.h? If yes, you have a circular dependency, and it's causing declarations to muck up.
EDIT 2:
You shouldn't just include all other headers from each of your headers. You should only include headers which are necessary. That's how you avoid these kinds of problems.
See section 4 of this article illustrates how to do this properly, and explains why this is happening:
http://www.cplusplus.com/forum/articles/10627/#msg49679
Last edited on Dec 12, 2013 at 12:55am UTC