Archived

This topic is now archived and is closed to further replies.

Laroche

Strange Inheritance Poblem

Recommended Posts

Laroche    140
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.

Share this post


Link to post
Share on other sites
Drath    138
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.

Share this post


Link to post
Share on other sites
Laroche    140

  
// 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.

Share this post


Link to post
Share on other sites
The Bear    122
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.



Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
The Bear    122
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]

Share this post


Link to post
Share on other sites