Thursday 11 April 2013

Question: How do you know that your class needs a virtual destructor?


Question: How do you know that your class needs a virtual destructor?

Answer: If your class has at least one virtual function, you should make a destructor for this class virtual. This will allow you to delete a dynamic object through a pointer to a base class object. If the destructor is non-virtual, then wrong destructor will be invoked during deletion of the dynamic object.

No comments:

Post a Comment