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

Answer Posted / guest

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 baller to a base
class object. If the destructor is non-virtual, then wrong
destructor will be invoked during deletion of the dynamic
object.

Is This Answer Correct ?    8 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Where and why do I have to put the "template" and "typename" keywords?

789


What is the difference between structure and class?

801


What is a v-table?

887


What do manipulators do?

760


What is the auto keyword good for in c++?

859


How is static data member similar to a global variable?

832


What are the various situations where a copy constructor is invoked?

835


What do you mean by global variables?

834


What is doubly linked list in c++?

831


Can member data be public?

776


Write about the various sections of the executable image?

756


What is the size of a vector?

803


What is diamond problem in c++?

765


If you want to share several functions or variables in several files maitaining the consistency how would you share it?

755


What is a storage class used in c++?

815