Virtual Function Problemo

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Pornomag
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 41
Joined: Tue Jun 21, 2011 5:39 am
Programming Language of Choice: C++

Re: Virtual Function Problemo

Post by Pornomag »

szdarkhack wrote:
Ginto8 wrote:If your issue is with a base type destructor, you're probably trying to delete a BaseImage* that actually stores a SWRImage2D. Now I couldn't find that situation in any of the posted code, but if that's the issue, just declare ~BaseImage() as virtual ie:

Code: Select all

virtual ~BaseImage() {}
This causes the compiler to call the destructor of SWRImage2D even when it's being stored as a BaseImage.
Damn, how did i miss that... Anyway, yes, anytime you use virtual functions it's a rule of thumb to make your base destructor virtual as well, otherwise you get some serious problems (depending on the occasion you can even slice your object in half and leak the base part). So make sure to always use virtual destructors when you want polymorphism :)
Thank you very much for your replies :) I feel like such a noob though ahhaha :P. Well I guess I am but still :P
Post Reply