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

What is a stack? How it can be implemented?

694


What is the purpose of template?

605


How can virtual functions in c++ be implemented?

607


Will the following program execute?

557


What is #include iomanip?

536






What is the best book for c++ beginners?

566


What is the use of turbo c++?

551


Are c and c++ different?

537


Define Virtual function in C++.

619


Which header file allows file i/o with streams a) fileio.h b) iostream.h c) fstream.h

653


What is class syntax c++?

590


Define macro.

585


Explain the use of virtual destructor?

620


Should a constructor be public or private?

535


What is a block in c++?

546