Page 2 of 2

Re: Virtual Function Problemo

Posted: Tue Sep 20, 2011 7:12 pm
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