Strange Inheritance Poblem

Started by
5 comments, last by Laroche 21 years, 1 month ago
My project was going along fine till I did a bunch of updates to it, and then something weird happened. Every header file game me the same error:

c:\nick\projects\hackslasher\cdynamicentity.h(9) : error C2504: ''CObject'' : base class undefined
 
Why would it suddenly stop working? I took out the changes (those I remember I did ), tried forward declaring the classes, but the error is ALWAYS there. How can I fix this? Im using Visual c++ 6.
Check out my music at: http://zed.cbc.ca/go.ZeD?user_id=41947&user=Laroche&page=content
Advertisement
I guess that that CObject just is not defined. you will need to make sure that these header files actually link to the header file containing CObject.

  // In CObject.h#ifndef CObj#define CObj#include <d3d8.h>#include <d3dx8.h>#include <string>#include <vector>#include <algorithm>#include <assert.h>#include "CAsset.h"#include "CSprite.h"#include "CTexture.h"#include "CRenderer.h"#include "CCamera.h"class CObject : public CAsset{public:	CObject(){ Clear(); }	~CObject(){ Release(); }	virtual void Clear();	virtual void Release();	void SetSprite(CSprite *p) { pSprite = p; }	void SetTexture(CTexture *p) { pTexture = p; }	void Draw();	virtual void GameUpdate(float FrameTime) = 0;	void SetCamera(CCamera *pCam) { pCamera = pCam; }	void SetScale(float NewScale) { Scale = NewScale; }	void SetLayer(int NewLayer) { Layer = NewLayer; }	void SetRender(CRenderer *p) { pRender = p; }	D3DXVECTOR2 GetPosition() { return Position; }	int GetLayer() { return Layer; }	CSprite * GetSprite() { return pSprite; }	CTexture * GetTexture() { return pTexture; }	CRenderer * GetRenderer() { return pRender; }	void SetPosition(D3DXVECTOR2 Pos);protected:	CSprite *pSprite;	CTexture *pTexture;	CRenderer* pRender;	CCamera *pCamera;	D3DXVECTOR2 Position;	float Scale;	int Layer;};#endif// Now in CDynamicEntity.h#ifndef CHeader#define CHeader#include "CObject.h"class CObject;enum DSTATE { DSTATE_NONE = 0, DSTATE_DRAW };class CDynamicEntity : public CObject{public:	CDynamicEntity(){ Clear(); }	~CDynamicEntity(){ Release(); }	virtual void Clear();	virtual void Release();	virtual void Update();	virtual void GameUpdate(float FrameTime);	void Rotate(float RadAmount);	void SetState(DSTATE d) { State = d; }	void SetDirection(float d) { Direction = d; }	void SetRadius(float r) { Radius = r; }	float GetVelocity() { return Velocity; }	float GetLimit() { return Limit; }	void SetLimit(float NewLimit) { Limit = NewLimit; }	void SetVelocity(float vVelocity) { Velocity = vVelocity; }	void IncreaseVelocity(float NewVelocity) { if (Velocity + NewVelocity > Limit) return; 												Velocity += NewVelocity; }private:	float Radius;	float Direction;	float Velocity;	float Limit;	DSTATE State;};#endif  


All of this was working fine before I changed some stuff, wish I knew what it was I did that broke it, because to my eyes this looks fine.
Check out my music at: http://zed.cbc.ca/go.ZeD?user_id=41947&user=Laroche&page=content
Two ideas come to mind:

1) If anybody else includes "CDynamicEntity.h", you could have a chicken and egg issue. Especially if any of your #ifndef/#endif pairs are broke.

2) If you made a backup and copied the files to a different directory or are working in a different directory, you may be looking in the wrong directory for the header files.



My money''s on two header guards with the same name. Something''s being included before CDynamicEntity.h and that header defines CObj.

By the way, take this stuff

  #include <string>#include <vector>#include <algorithm>#include <assert.h>  

Out of the header CObject.h and into the implementation file to reduce your compile times.
No, that won''t work. Then it won''t find the definitions for thoes classes.

-----------------------------
Gamedev for learning.
libGDN for putting it all together.
IMO it's best to keep as few "#include"s in your header file as possible (e.g. your header file is not using string). Place them in your ".cpp". You may have to include things like "CObject" more often (again, in the ".cpp"), but it won't be included in *every* file. Beleive me, it can decrease your compile time and decrease the number of headaches that you get from issues like this. Also, when your header file simply references classes by pointers, use "class MyClass" at the top instead of "#include" ~ even if you have to "#include" it many more times in the ".cpp".

As the AP suggested, check all of your header guards. Then if that does not work, remove all the includes in "CObject.h" and add them back one-by-one to see which "#include" is the culprit. If it's the first one, "CAsset.h", look at that file *very* carefully.


[edited by - PropellerBoy on March 5, 2003 7:30:14 PM]

This topic is closed to new replies.

Advertisement