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
Explain virtual inheritance?
They started with the brief introduction followed by few basic C++ questions on polumorphism, inheritance and then virtual functions. What is polymorphims? How you will access polymorphic functions in C? How virtual function mechanism works?
What is polymorphism in oops?
What is a function in oop?
What is solid in oops?
Is abstract thinking intelligence?
What is the types of inheritance?
Prepare me a program for the animation of train
What is encapsulation example?
They started with the brief introduction followed by few basic C++ questions on polumorphism, inheritance and then virtual functions. What is polymorphims? How you will access polymorphic functions in C? How virtual function mechanism works?
Where is pseudocode used?
What is the diamond problem in inheritance?
What is overloading in oop?
write string class as your own class in java without using any built-in function
can inline function declare in private part of class?