How to force a particular destructor?

Started by
1 comment, last by Sailorstick 20 years, 10 months ago
Example:

Form::~Form(){
	Window* ctrl=this->controls;
	Window* temp;
	while(ctrl!=NULL){
		temp = ctrl->next;
		delete ctrl;
		ctrl = temp;
	}
}
Window is an abstract class and has no destructor of it''s own. I have a RoundTree control that is inherited from an abstract class TreeView (again, no destructor) which is inherited from Window. So, RoundTree is a Window which I am able to add to Form->controls. Problem is, when I delete a form, the Form destructor gets called but the line "delete ctrl;" never calls the RoundTree destructor and I get huge memory leaks. How can I force it to be called?
Advertisement
Add a virtual destructor to the Window class.
Groovy.

This topic is closed to new replies.

Advertisement