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 is difference between c++ and c ++ 14?
Write a short code using c++ to print out all odd number from 1 to 100 using a for loop
Is it possible to use a new for the reallocation of pointers ?
What are the 3 levels of programming languages?
Explain storage qualifiers in c++.
What is a block in c++?
Write a program for Divide a number with 2 and Print the output ( NOTE: Check for divide by zero error).
Can I have a reference as a data member of a class? If yes, then how do I initialise it?
What is c++ best used for?
What is the function of I/O library in C++ ?
Who was the creator of c++?
What do you know about near, far and huge pointer?
What is the use of endl in c++ give an example?
What happens when the extern "c" char func (char*,waste) executes?
What is a v-table?