Sign in to follow this  

class inheritence

This topic is 3585 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
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

This topic is 3585 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this