From: Larry Lindstrom on
Hi Folks:

Developing on XP Home, VS 2008, C++.

If I delete a derived class, which has a destructor, shouldn't
the destructor of base class be called automatically?

The derived class's destructor is being called, but the base
class's destructor isn't. Do I have to delete the base class
from the derived class's destructor?

Thanks
Larry
From: Alf P. Steinbach on
* Larry Lindstrom:
>
> If I delete a derived class, which has a destructor, shouldn't
> the destructor of base class be called automatically?

Unless you have undefined behavior, a hang, or program termination.


> The derived class's destructor is being called, but the base
> class's destructor isn't. Do I have to delete the base class
> from the derived class's destructor?

No, never do that.

Chances are you're doing something like

Base* p = new Derived;
delete p;

where Base doesn't have a virtual destructor.

This would be undefined behavior.

Otherwise, post complete (can be compiled & run) but minimal example code.



Cheers, & hth.,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
From: Larry Lindstrom on
Alf P. Steinbach wrote:
> * Larry Lindstrom:
>>
>> If I delete a derived class, which has a destructor, shouldn't
>> the destructor of base class be called automatically?
>
> Unless you have undefined behavior, a hang, or program termination.
>
>
>> The derived class's destructor is being called, but the base
>> class's destructor isn't. Do I have to delete the base class
>> from the derived class's destructor?
>
> No, never do that.
>
> Chances are you're doing something like
>
> Base* p = new Derived;
> delete p;
>
> where Base doesn't have a virtual destructor.
>
> This would be undefined behavior.
>
> Otherwise, post complete (can be compiled & run) but minimal example code.

Thanks Alf:

I bet that's it.

I've called the functions needed to properly shut down the app,
it was being hung waiting for a disconnect for the database, and
I'll do the virtual destructor soon.

Thanks
Larry