Jump to content
  • Advertisement

Archived

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

AlexM

derived class destruct

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

i have a base class and a bunch of classes derived from it. Then my program basically calls the base class functions, but the class could in fact be any of the derived classes. the program doesn''t care and the function calls go through ok, except the destructor. i have to explicitely create a CleanUp function for each class and call it. ex: class baseclass { func1; baseclass(); CleanUp(); ~baseclass(); }; class c1 : public baseclass { func1; c1(); CleanUp(); ~c1(); } class c2 : public baseclass { func1; c2(); CleanUp(); ~c2(); } baseclass *c = new c2; c->func1(); //works perfectly, calls c2 func1 but i can''t do this: delete c; //it calls the baseclass destructor, not c2 destr i have to explicity: c->CleanUp(); //c2 CleanUp func is called... delete c; Any way to get around this? I don''t want to have to worry about calling CleanUp(). And yes, i tried putting a call to overridable CleanUp in baseclass destructor - it calls the baseclass CleanUp only!

Share this post


Link to post
Share on other sites
Advertisement
Are your Destructors defined as virtual?



class CBaseClass
{
public:
CBaseClass();
virtual ~CBaseClass();
};

class CDerivedClass
{
public:
CDerivedClass();
virtual ~CDerivedClass();
};

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!