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

Function can be overloaded based on the parameter which is a value or a reference. Explain if the statement is true.

641


What is flush programming?

561


Why do we use using namespace std in c++?

595


Explain terminate() function?

587


Why do we need c++?

589






What is static function? Explain with an example

551


How are Structure passing and returning implemented by the compiler?

591


Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the maximum number of concurrent threads that the InnoDB plug-in can create

2059


How can you tell what shell you are running on unix system?

627


Is it possible to provide special behavior for one instance of a template but not for other instances?

626


What is null pointer and void pointer and what is their use?

574


What is function prototyping?

609


What is heap sort in c++?

591


What is this weird colon-member (" : ") syntax in the constructor?

534


What is a far pointer? where we use it?

606