How do you know that your class needs a virtual destructor?
Answer Posted / som shekhar
If we are deriving from the base class and the base class
consist of some virtual function , then in this case the
base destructor should be virtual.
if you do some thing like this :
base* b = new derived;
delete b;
In this case if base destructor is NOT VIRTUAL then only
base destructor is called and derived destructor wont be
called resulting into memory leak.
But if the base destructor is virtual then derived class
destructor and base destructor both will be called.
Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What are the methods of exporting a function from a dll?
What data structure is fastest, on average, for retrieving data: a) Binary Tree b) Hash Table c) Stack
What is the function to call to turn an ascii string into a long?
How can you say that a template is better than a base class?
Describe the setting up of my member functions to avoid overriding by the derived class?
What are proxy objects in c++?
What is input operator in c++?
How is new() different from malloc()?
What are manipulators in c++ with example?
What are arithmetic operators?
What is static in c++?
What is decltype c++?
What is the difference between structure and class?
Difference between pointer to constant and constant pointer to a constant. Give example.
Why are arrays usually processed with for loop?