Re: Odd error with g++



On Saturday 21 Jan 2006 19:17 in article
<1137871047.763997.136900@xxxxxxxxxxxxxxxxxxxxxxxxxxxx> of
comp.os.linux.development.apps, elitecodex wrote:

> Fixed it.
>
> I did a little bit more research and just tried something... and it
> worked. I just added virtual to my deconstructor.

Presumably in the parent class.

> Any ideas as to why that would fix it? What does the deconstructor
> being virtual have to do with a method of being virtual?

All destructors should be virtual! [Moreover, the destructor is a
method.]

Having the destructor virtual ensures that the appropriate chain of
events up and down the inheritance hierarchy are scheduled so that
clean-ups of all appropriate classes can take place on the instance.
This prevents memory leaks, closes any dangling file descriptors, and
cleans up any other system resources that parent classes have used and
are unknown to descendant classes, or descendant classes have used and
are unknown to parent classes. It is very important!

Scott Meyers has written at length on this in years gone by. I
*strongly* recommend you read his two books: "Effective C++" and "More
Effective C++". These will tell you about this and various other
pitfalls that await C programmers who are trying their hands at C++.

--
Regards

Dave [RLU#314465]
======================================================
dwnoon@xxxxxxxxxxxxxxxxxxxxx (David W Noon)
Remove spam trap to reply via e-mail.
======================================================

.