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
Explain the use of virtual destructor?
How many types of modularization are there in c++?
What is a storage class?
How can you create a virtual copy constructor?
What is a singleton class c++?
What is an object in c++?
What is dev c++ used for?
What language does google use?
What are register variables?
what is C++ exceptional handling?
What is the size of a vector?
What c++ library is string in?
When can I use a forward declaration?
Explain "const" reference arguments in function?
What is long in c++?