C++ virtual deconstructor

Started by
4 comments, last by ChopperDave 17 years, 6 months ago
On this recent thread... click jfclavette asks some example questions and one of them is... - Why should a destructor never be virtual in C++ ? I was wondering why this is, with my understanding, having a virtual deconstructor would cause the deconstructor of a class that was dirived from this class to be called. Which is really important... But, I didn't know if I was wrong or if this was a trick question. Thanks for the help
~Mark Schadler
Advertisement
Yeah, my understanding's the same as yours. I thought destructors are necessary for inheritance to work right...
Making a base class destructor non virtual is one way of documenting that you don't want people to derive from your class.

Cheers
Chris
CheersChris
It was, indeed, a trick question.

CM
Thanks a lot for the clarification guys... I thought it was too serious to have a trick question but I guess I was wrong.
~Mark Schadler
Check out this article here. Read section 20.4.

This topic is closed to new replies.

Advertisement