# class inheritence

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

## 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 on other sites
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 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 on other sites
A function called Destroy is not a destructor, but maybe you meant to write a destructor instead.

##### 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 on other sites
Quote:
 Original post by RDragon1A 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 on other sites
Quote:
Original post by Oni Sephiroth
Quote:
 Original post by RDragon1A 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 on other sites
Quote:
Original post by Oni Sephiroth
Quote:
 Original post by RDragon1A 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.)

1. 1
2. 2
Rutin
23
3. 3
4. 4
frob
16
5. 5

• 9
• 33
• 13
• 12
• 10
• ### Forum Statistics

• Total Topics
632579
• Total Posts
3007168

×