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
Explain overriding.
What are iterators in c++?
Explain the different access specifiers for the class member in c++.
How compile and run c++ program in turbo c++?
What is microsoft c++ redistributable 2013?
What is a stack? How it can be implemented?
What is a driver program?
Show the declaration for a static member variable.
Is set c++?
What is virtual destructor ans explain its use?
What is the hardest coding language to learn?
Are c and c++ different?
Do class declarations end with a semicolon? Do class method definitions?
What jobs can you get with a c++ certification?
Can a built-in function be recursive?