On Wed, 18 Nov 2009, John Peterson wrote:
On Wed, Nov 18, 2009 at 1:30 AM, Tim Kroeger
<[email protected]> wrote:
On Tue, 17 Nov 2009, John Peterson wrote:
As I understand the way destructors work, if you delete an object of
type derived through an object of type pointer-to-base, as long as the
base class destructor is declared virtual, the derived class
destructor will be called *in addition to* the destructor for *every*
intermediate type. Correct?
This is always done, no matter whether the destructor is virtual or not.
I don't think so. After sending that email, I wrote a test code and
in fact the destructor does need to be virtual for the destructor to
travel "all the way" up the chain. Try the test code below with and
without virtual commented...
I see, there has been a misunderstanding. Of course, if the
destructor is not virtual and you delete the object as an instance of
A, only A's destructor is called. But if you delete it as an instance
of C, all destructors are called. You can see that by changing the
line
A* a = new C;
of your code to
C* a = new C;
This is what I meant. In other words, without a virtual destructor,
you might miss to call the destructor of the derived class, but you
can never miss to call the destructor of the base class.
Best Regards,
Tim
--
Dr. Tim Kroeger
[email protected] Phone +49-421-218-7710
[email protected] Fax +49-421-218-4236
Fraunhofer MEVIS, Institute for Medical Image Computing
Universitaetsallee 29, 28359 Bremen, Germany
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Libmesh-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libmesh-devel