when can we use virtual destructor?

Answer Posted / sagarson

Need for a virtual destructor
1.destructor for the base parts are invoked automatically
2.we might delete a ptr to the base type that actually
points to a derived object
3.if we delete a ptr to base then the base class destructor
is run and the members of the base class are cleared up. If
the object is a derived type then the behavior is undefined
4.to ensure that the proper destructor is run the destructor
must be virtual in the base class
5.virtual destructor needed if base pointer that points to a
derived object is ever deleted (even if it doesnt do any work)

Is This Answer Correct ?    34 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the use of virtual destructor?

620


How many types of modularization are there in c++?

562


What is a storage class?

643


How can you create a virtual copy constructor?

580


What is a singleton class c++?

542






What is an object in c++?

609


What is dev c++ used for?

603


What language does google use?

587


What are register variables?

643


what is C++ exceptional handling?

627


What is the size of a vector?

575


What c++ library is string in?

572


When can I use a forward declaration?

624


Explain "const" reference arguments in function?

610


What is long in c++?

735