Re: base class virtual destructor not resolving inherited virtual functions
- From: "Bo Persson" <bop@xxxxxx>
- Date: Fri, 18 Aug 2006 23:55:26 +0200
"Dan Baker" <dbmail> skrev i meddelandet
news:eR2jebwwGHA.4200@xxxxxxxxxxxxxxxxxxxxxxx
"Doug Harrison [MVP]" <dsh@xxxxxxxx> wrote in message
news:a47ce2tot9jk90fondglsa9o1covgm5gv0@xxxxxxxxxx
On Fri, 18 Aug 2006 13:03:06 -0600, "Dan Baker" <dbmail> wrote:
I have a heavy fog over my brain, and can't see the obvious
answer...
I have a base class "CBase" and an inherited class "CChild". I
instantiate
an object of "CChild", work with it, and then delete it. It has an
empty
destructor, which does nothing, and then calls the CBase
destructor, which
calls a virtual function which is overridden in CChild -- BUT, it
doesn't
call the overriden function (it is simply calling the base class
function).
What am I not seeing here?
In C++, virtual functions called from ctors and dtors never resolve
to
versions overridden by derived classes, because the derived parts
don't
exist at those times. C++ is unlike (and superior to) Java and C#
in this
respect.
Excellent information. I have fixed it already -- I added a
"Destroy" function that the CChild::~CChild can call to get
everything cleaned up nicely.
You shouldn't really need that. Each destructor handles the
destruction of its own part of the inheritance structure.
All of the virtual destructors are called, in reverse order (~Base
last).
Bo Persson
.
- References:
- base class virtual destructor not resolving inherited virtual functions
- From: Dan Baker
- Re: base class virtual destructor not resolving inherited virtual functions
- From: Doug Harrison [MVP]
- Re: base class virtual destructor not resolving inherited virtual functions
- From: Dan Baker
- base class virtual destructor not resolving inherited virtual functions
- Prev by Date: Re: CMemoryException
- Next by Date: Duplicate entries in drop down box
- Previous by thread: Re: base class virtual destructor not resolving inherited virtual functions
- Next by thread: Re: base class virtual destructor not resolving inherited virtual functions
- Index(es):
Relevant Pages
|