What is virtual destructor? Why?
Answer Posted / sagarika patra
When a destructor is declared as virtual in the base class
is known as virtul destructor.
Whenever any object of derived class of base type is freed
(using delete operator),the destructor of the derived class
is called and the memory allocated by derived class
variables are freed ,leaving the memory allocated by the
base class variables as unfreed.
Hence by declaring the base class destructor as
virtual,both the destructor will called in order.
Is This Answer Correct ? | 9 Yes | 0 No |
Post New Answer View All Answers
#include
is there any choice in opting subjects like 4 out of 7
What is the use of oops?
Who invented oop?
What is encapsulation in simple terms?
What are the important components of cohesion?
Can abstract class have normal methods?
What is data binding in oops?
What is variable example?
What are two types of polymorphism?
Why multiple inheritance is not possible?
What is object in oop with example?
when to use 'mutable' keyword and when to use 'const cast' in c++
Why do we need oop?
What is encapsulation with example?