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
Can I make ios apps with c++?
What are the differences between the function prototype and the function defi-nition?
Explain the static member function.
What does it mean to declare a member function as static?
What are the uses of pointers?
Please explain the reference variable in c++?
what are the events occur in intr activated on interrupt vector table
In int main(int argc, char *argv[]) what is argv[0] a) The first argument passed into the program b) The program name c) You can't define main like that
What are the various storage classes in C++?
why is iostream::eof inside a loop condition considered wrong?
What is srand c++?
When must you use a pointer rather than a reference?
What are virtual constructors/destructors?
Give 10 points of differences between C & C++.
Can non graphic characters be used and processed in C++?