non virtual TObject::~TObject()

William J Deninger (deninger@uiuc.edu)
Thu, 9 Apr 1998 20:58:34 -0500


This is a multi-part message in MIME format.

------=_NextPart_000_0023_01BD63FA.42B824A0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hello,=20

Fred Gray has recently informed me of the procedure by which destructors =
are called and the difference between virtual and non virtual =
destructors implementation. Apparently for non virtual destructors, all =
inherited base destructors are called up to the level of the pointer =
type passed to delete. Whereas with virtual destructors, all inherited =
base destructors are called up to the level of the instantiated type.

Given the class hierarchy=20
class TCClass : publicTBClass
{
...
}

class TBClass : public TAClass
{
...
}

where
TBClass *b =3D new TCClass;
delete b;

then :
1) if all classes have virtual destructors --> ~TAClass(), =
~TBClass(), ~TCClass
2) if all classes have NON virtual destructors --> ~TAClass(), =
~TBClass()=20

If this is correct, shouldn't root classes (such as TObject or any root =
class allowed to be inherited) have their destructors implemented as =
virtual? =20

William J Deninger

------=_NextPart_000_0023_01BD63FA.42B824A0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">

 
Hello,
 
Fred Gray has recently informed me of the procedure = by which=20 destructors are called and the difference between virtual and non = virtual=20 destructors implementation.  Apparently for non virtual = destructors, all=20 inherited base destructors are called up to the level of the pointer = type passed=20 to delete.  Whereas with virtual destructors, all inherited base=20 destructors are called up to the level of the instantiated = type.
 
Given the class hierarchy
class TCClass : publicTBClass
{
...
}
 
class TBClass : public TAClass
{
...
}
 
where
TBClass *b =3D new TCClass;
delete b;
 
then :
 1)   if all classes = have virtual=20 destructors -->  = ~TAClass(),=20 ~TBClass(), ~TCClass
 2)   if all classes = have NON=20 virtual destructors --> = ~TAClass(),=20 ~TBClass()
 
If this is correct, shouldn't root = classes (such=20 as TObject or any root class allowed to be inherited) have their = destructors=20 implemented as virtual? 
 
William J = Deninger
------=_NextPart_000_0023_01BD63FA.42B824A0--