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
Write about the various sections of the executable image?
What is purpose of abstract class?
To what does “event-driven” refer?
What is c++ mutable?
List the advantages of inheritance.
What is meant by entry controlled loop? What all C++ loops are exit controlled?
What are dynamic type checking?
What is a stack c++?
Is it legal in c++ to overload operator++ so that it decrements a value in your class?
What are the implicit member functions of class?
What is endl c++?
What are c++ tokens?
What do you mean by function overriding & function overloading in c++?
What is a manipulative person?
Explain linked list using c++ with an example?