Answer Posted / uma sankar pradhan
A virtual destructor is needed when we are deleting a
object of derived class using a base class pointer.
i.e.,
base *b=new derived;
delete(b);
Let's say,we have allocated memory dynamically in derived
class constructor to a pointer data member and we
deallocated it in the destructor to avoid memory leakage
When the object is deleted through base class pointer,
only the base class destructor is invoked.consequently,the
dynamically allocated space remains unreleased.so it leads
to memory leak
| Is This Answer Correct ? | 34 Yes | 1 No |
Post New Answer View All Answers
What is a null tree?
What is the difference between procedural programming and oops?
What is polymorphism in oops with example?
What is Difeerence between List obj=new ArrayList(); and ArrayList obj=new ArrayList()?
Can private class be inherited?
Can we create object of interface?
What is class and example?
State what is encapsulation and friend function?
How Do you Code Composition and Aggregation in C++ ?
Why do we use class in oops?
What is inheritance write a program to show use of inheritance?
Can a destructor be called directly?
What do you mean by variable?
Why we use classes in oop?
what's the basic's in dot net