Advertisement

weird inheritence problem

Started by June 15, 2002 05:58 PM
8 comments, last by Laroche 22 years, 6 months ago
I have a class called CObject and a class called CPlayer. I want CPlayer to publibly inherit from CObject. So, in the class declaration, i do class CPlayer : public CObject; fairly simple. However, for some strange reason, I get the following error message.. error C2504: ''CObject'' : base class undefined What does a class have to do to become "defined"? p.s: yes, i included "CObject.h" in my "CPlayer.h"
Check out my music at: http://zed.cbc.ca/go.ZeD?user_id=41947&user=Laroche&page=content
Show us some of your code.

/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/
/*=========================================// Chem0sh// Lead Software Engineer & Tech Support// http://www.eFaces.biz=========================================*/
Advertisement
here is CObject.h

  #ifndef _Nicks_CObject#define _Nicks_CObject#include "CGame.h"class CSprite;class CObject{public:	// Constructor / Destructor	CObject();	virtual ~CObject() = 0;		// Methods	void SetSpritePointer(CSprite *ps) { pSprite = ps; }	void Draw(RECT &rSource, RECT &rDestination);	void SetWorldXPosition(int NewXPosition) { WorldXPosition = NewXPosition; }	void SetWorldYPosition(int NewYPosition) { WorldYPosition = NewYPosition; }	void SetLocalXPosition(int NewXPosition) { LocalXPosition = NewXPosition; }	void SetLocalYPosition(int NewYPosition) { LocalYPosition = NewYPosition; }		// Accessor	int GetWorldX() { return WorldXPosition; }	int GetWorldY() { return WorldYPosition; }	int GetLocalX() { return LocalXPosition; }	int GetLocalY() { return LocalYPosition; }	int GetBoxX() { return rBoundingBox.top; }	int GetBoxY() { return rBoundingBox.right; }	RECT GetUpPic() { return rUpPic; }	RECT GetLeftPic() { return rLeftPic; }	RECT GetRightPic() { return rRightPic; }	RECT GetDownPic() { return rDownPic; }protected:	RECT rBoundingBox;	int WorldXPosition;	int WorldYPosition;	int LocalXPosition;	int LocalYPosition;	CSprite *pSprite;	RECT rLeftPic;	RECT rRightPic;	RECT rUpPic;	RECT rDownPic;};#endif  


And here is CPlayer.h

  #ifndef _CPlayer#define _CPlayer#include "CObject.h"#include "CGame.h"class CPlayer : public CObject{public:	 CPlayer()	{		SetRect(&rLeftPic, 199, 1, 230, 32);		SetRect(&rRightPic, 67 ,1, 98, 32);		SetRect(&rUpPic, 133, 1, 164, 32);		SetRect(&rDownPic, 1, 1, 32, 32);		SetRect(&rBoundingBox, 0, 0, 32, 32);	}	 virtual ~CPlayer(){};private:	char* Name;};#endif  
Check out my music at: http://zed.cbc.ca/go.ZeD?user_id=41947&user=Laroche&page=content
CObject is an abstract class (it contains a pure virtual method - the destructor), meaning an instance of it can never be created, yet it has no virtual methods other than the destructor. Do you define those methods (Set_/Get_xx) somewhere? They should all be virtual so a derived class can inherit and override if necessary, or fall back on the base version.
Hmm just made all the set/gets virtual, but it doesn''t seem to solve my problem. In case you were wondering why the ADT has no other virtuals, it''s because i haven''t finnished these classes yet, they are in a sort of BETA phase right now. Once I get what I have to work, i''ll add more (methods).
Check out my music at: http://zed.cbc.ca/go.ZeD?user_id=41947&user=Laroche&page=content
You cannot have pure virtual destructors.
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
Advertisement
quote: Original post by dalleboy
You cannot have pure virtual destructors.


Yes, you can. It''s usually the ''default'' choice when you want to make a class abstract, but do not have a function you want to make pure virtual.

However, you mustprovide an implementation for the destructor even though it is declared pure virtual.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
quote: Original post by Fruny
Yes, you can.
Well, I''ll be damned. I thought I was so smart...

I was always using protected constructors instead.

Thank you for enlightening me.
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
This is a very annoying problem, which I''m sure has a very easy solution. I Don''t know what else to try, so even if your not sure if it would work, post it anyways please. I''m desperate
Check out my music at: http://zed.cbc.ca/go.ZeD?user_id=41947&user=Laroche&page=content
The only reason that you will have this problem is that CObject is not visible to CPlayer for some reason. You quite possibly haven''t set-up your project configuration correctly, or maybe you''ve spelt something wrong. I also find CObject to be a dodgy class-name to use, knowing that MS have their own class with the same name.

This topic is closed to new replies.

Advertisement