Skip to main content
GameDev.net gamedev.net
๐Ÿ”’ Locked

C++ virtual deconstructor

Started by Stiffler Oct 6, 2006 at 4:59 PM 4 replies 2.7k views
Original Post
Stiffler
Stiffler
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
TheOddMan
TheOddMan
Yeah, my understanding's the same as yours. I thought destructors are necessary for inheritance to work right...
chollida1
chollida1
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
Stiffler
Stiffler
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.