Advertisement

Base class undefined

Started by February 22, 2003 09:17 AM
2 comments, last by DaJero 21 years, 8 months ago
I am using Visual C++ 6 Introductionary edition. I have three classes: GameObject, TexturedObject and Input. The last two are children of the GameObject. Everytime I try to compile my source code I get these two errors: c:\documents and settings\jeroen\my documents\c++\shooty\texturedobject.h(11) : error C2504: 'GameObject' : base class undefined c:\documents and settings\jeroen\my documents\c++\shooty\input.h(13) : error C2504: 'GameObject' : base class undefined I hope someone will be able to help me. It's really fustrating. I don't know what's wrong. Here's the source code of gameobject.h, texturedobject.h and input.h:
    
#ifndef GAMEOBJECT_H
#define GAMEOBJECT_H

#include "engine.h"

class Engine;

class GameObject
{
protected:
	Engine *E;
public:
	GameObject(Engine *NewEngine);
	GameObject *Next;
};

#endif
  

    
#ifndef TEXTUREDOBJECT_H
#define TEXTUREDOBJECT_H

#include "gameobject.h"
#include "engine.h"

class Engine;
class GameObject;

class TexturedObject : public GameObject
{
protected:
	NDX_Surface *Surface;
	char *FileName;
	float X;
	float Y;
public:
	TexturedObject(Engine *NewEngine, char *_FileName);

	NDX_Surface* GetSurface();
	void SetPos(float NewX, float NewY);
	float GetX() { return X; }
	float GetY() { return Y; }
	void SetTransparentColor(bool UseTransP, DWORD Color);
};

#endif  
  

  
#ifndef INPUT_H
#define INPUT_H

#include "gameobject.h"
#include "texturedobject.h"
#include "engine.h"

class Engine;
class GameObject;
class TexturedObject;

class Input : public GameObject
{
protected:
	NDX_Input *I;
	TexturedObject *Cursor;
public:
	Input(Engine *NewEngine, NDX_Window *Window);
	~Input();
	void HandleInput();
};

#endif  
  
Thanks a lot in advance, DaJero - Oderint dum metuant [edited by - DaJero on February 22, 2003 10:19:19 AM]
DaJero- Oderint dum metuant
Remove declarations of classes in each file, you something like this:

class Engine; // Remove this and the others declarations like this
class Input : public GameObject
{
};

...and try it out.

Advertisement
protected: is a keyword that limits access to a class'' member functions and variables. Only the class itself and any derived classes are allowed to access protected members.
OK,

I removed every class forward in the header files, and now the number of errors went up to 61(!). I have included the current code in all header files (engine.h, gameobject.h, texturedobject.h and input.h)


    #ifndef ENGINE_H#define ENGINE_H#include <NukeDX.h>#include "gameobject.h"#include "texturedobject.h"#include "input.h"#include <string>using namespace std;class Engine{private:	NDX_Screen *Screen;	NDX_Window *Window;	NDX_Log *PrvtLog;	Input *I;	HINSTANCE hInst;	HINSTANCE hPrevInstance;	LPSTR lpszCmdParam;	int nCmdShow;public:	Engine(HINSTANCE _hInst,HINSTANCE _hPrevInstance,LPSTR _lpszCmdParam,int _nCmdShow, int ResX, int ResY);	~Engine();	NDX_Screen* GetScreen();	bool MainLoop();	GameObject* AddObject(GameObject *NewObject);	void Log(string Text);public:	float Scale;	GameObject *Objects;};#endif  



  #ifndef GAMEOBJECT_H#define GAMEOBJECT_H#include "engine.h"class GameObject{protected:	Engine *E;public:	GameObject(Engine *NewEngine);	GameObject *Next;};#endif  



  #ifndef INPUT_H#define INPUT_H#include "gameobject.h"#include "texturedobject.h"#include "engine.h"class Input : public GameObject{protected:	NDX_Input *I;	TexturedObject *Cursor;public:	Input(Engine *NewEngine, NDX_Window *Window);	~Input();	void HandleInput();};#endif  



  #ifndef TEXTUREDOBJECT_H#define TEXTUREDOBJECT_H#include "gameobject.h"#include "engine.h"class TexturedObject : public GameObject{protected:	NDX_Surface *Surface;	char *FileName;	float X;	float Y;public:	TexturedObject(Engine *NewEngine, char *_FileName);	NDX_Surface* GetSurface();	void SetPos(float NewX, float NewY);	float GetX() { return X; }	float GetY() { return Y; }	void SetTransparentColor(bool UseTransP, DWORD Color);};#endif  


I really hope someone will be able to help me.

Thanks a lot in advance,

DaJero
- Oderint dum metuant

[edited by - DaJero on February 22, 2003 12:29:26 PM]
DaJero- Oderint dum metuant

This topic is closed to new replies.

Advertisement