Jump to content
  • Advertisement
Sign in to follow this  
Oni Sephiroth

class inheritence

This topic is 3953 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So, I have a base class and a derived class..
class CBase_Arrow
{
protected:
	unsigned char * Sprite;
	int Type;
	void Destroy();
};

class CArrow : public CBase_Arrow
{
public:
	CArrow();
};
Now I'm trying to define the Destroy() function for the derived class like so..
/*void CArrow::Destroy()
{
	delete ArrowNorm;
}*/
(commented out because it isn't working..) ...aaand it's not liking it for some reason. error C2509: 'Destroy' : member function not declared in 'CArrow' I'm not having problems with the Type variable, which is also derived, so I don't understand this at all.

Share this post


Link to post
Share on other sites
Advertisement
Quote:

class CArrow : public CBase_Arrow
{
public:
CArrow();
};


I don't see any function called Destroy declared in CArrow, just like the compiler said.

Share this post


Link to post
Share on other sites
You should implement your destructor in CBase_Arrow, not in CArrow. In your code it is declared in Arrow.

Probably you want to make destuctor virtual. If so, use the following:
class CBase_Arrow
{
protected:
super_arrow_class *ArrowNorm;
unsigned char * Sprite;
int Type;
virtual void Destroy();

};

class CArrow : public CBase_Arrow

{

public:

CArrow();
void Destroy();
};

void Arrow::Destroy()

{
delete ArrowNorm;
}

void CArrow::Destroy()

{
CBase_Arrow::Destroy();
}

Share this post


Link to post
Share on other sites
You must declare the Destroy function in CArrow also. This is a requirement in the derived class when you are overriding a base class function. You need:

class CArrow : public CBase_Arrow
{
public:
CArrow();
protected:
void Destroy();
};

Share this post


Link to post
Share on other sites
Quote:
Original post by RDragon1
A function called Destroy is not a destructor, but maybe you meant to write a destructor instead.


No, i'm not writing a destructor.

Quote:
You must declare the Destroy function in CArrow also. This is a requirement in the derived class when you are overriding a base class function. You need:


ah, thanks, news to me.

Share this post


Link to post
Share on other sites
Quote:
Original post by Oni Sephiroth
Quote:
Original post by RDragon1
A function called Destroy is not a destructor, but maybe you meant to write a destructor instead.


No, i'm not writing a destructor.

Quote:
You must declare the Destroy function in CArrow also. This is a requirement in the derived class when you are overriding a base class function. You need:


ah, thanks, news to me.


Obligatory C++ FAQ link

Share this post


Link to post
Share on other sites
Quote:
Original post by Oni Sephiroth
Quote:
Original post by RDragon1
A function called Destroy is not a destructor, but maybe you meant to write a destructor instead.


No, i'm not writing a destructor.


Why are you writing a function called "Destroy" instead of a destructor? What will cause it to be called? What will you do with the object after "Destroy"ing it? (Keep in mind that it still exists somewhere. The destructor is code that is automatically called, immediately before the object ceases to exist.)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!