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
What is a list c++?
How can you quickly find the number of elements stored in a static array? Why is it difficult to store linked list in an array?
Can a built-in function be recursive?
Explain selection sorting?
Can a program run without main function?
Can we declare a base-class destructor as virtual?
Explain the use of this pointer?
How do you establish an is-a relationship?
What is difference between rand () and srand ()?
What is prototype for that c string function?
What is the meaning of c++?
What are friend functions in C++?
How does a C++ structure differ from a C++ class?
How to declare a pointer to an array of integers?
What ANSI C++ function clears the screen a) clrscr() b) clear() c) Its not defined by the ANSI C++ standard