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 implicit member functions of class?
Where do I find the current c or c++ standard documents?
How will you call C functions from C ++ and vice-versa?
When do you call copy constructors?
Write a program to interchange 2 variables without using the third one.
How can we check whether the contents of two structure variables are same or not?
Explain class invariant.
What is a set in c++?
What do you mean by enumerated data type?
What are the types of container classes?
How do we implement inheritance in c++?
What is the full form of ios?
Explain how to initialize a const data member.
What do you mean by function and operator overloading in c++?
What are stacks?