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 capacity in vector in c++?

547


How is c++ different from java?

561


Explain register storage specifier.

595


What is encapsulation in c++ with example?

586


What are the advantages of using a pointer?

607






Is c++ proprietary?

582


What is #include cstdlib in c++?

661


What are built-in functions? What is the syntax for the definition?

567


What does it mean to declare a member function as virtual?

585


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

2072


How can you link a c program with a c function?

567


When do we use copy constructors?

596


Which coding certification is best?

570


How do you invoke a base member function from a derived class in which you’ve overridden that function?

582


Explain what happens when a pointer is deleted twice?

733