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
How do you write a function that can reverse a linked-list?
What is the difference between global variables and local variable
Can a program run without main?
What is token c++?
What is the benefit of learning c++?
What is a lambda function c++?
What are features of c++?
Differentiate between an inspector and a mutator ?
Explain selection sorting. Also write an example.
True or false, if you keep incrementing a variable, it will become negative a) True b) False c) It depends
Why are pointers not used in c++?
What is jump statement in C++?
Define a conversion constructor?
What is a singleton c++?
What is pointer in c++ with example?