when can we use virtual destructor?

Answer Posted / n

Virtual Destructor is a concept, comes into picture when one
will try to delete the base object pointer pointing to
derived class.
Base* pb = new Derived();
delete pb;
In this case if Base class destructor is not virtual then
only base class destructor will be called up for clean up.

While if we make Base class destructor as virtual then
1. Derived class destructor will be called
2. Base class destructor will be called up

Proper clean up of the objects from derived as well as base
class. Mission Accomplish

Is This Answer Correct ?    36 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you sort a sort function in c++ to sort in descending order?

766


What is the use of namespace std in C++?

793


What is scope operator in c++?

786


What is the difference between method overloading and method overriding in c++?

752


What is the difference between equal to (==) and assignment operator (=)?

754






What is virtual base class?

739


Which software is best for c++ programming?

753


Do vectors start at 0?

748


Differentiate between the manipulator and setf( ) function?

803


What is a string example?

736


What are punctuators in c++?

849


Is swift faster than go?

836


What are smart pointers?

1187


what are the iterator and generic algorithms.

1658


What is #include cmath?

824