Explain the need for "Virtual Destructor".

This question is related to TCS Interview

Showing Answers 1 - 4 of 4 Answers

devi

  • Jul 29th, 2006
 

if both the base class and derived class can have the constructors,if the derived class is to call the constructor of its own using its object,it can.but when it calls its destructor,the compiler calls the destructor of base class.thats why the virtual destructor concept is coined. but there are no virtualconstructors

Whenever In inheritance hierarchy we access the objects of derived class by using generic pointer, and now we need to destroy the object, at this point the destructor of that class is called to whom generic pointer belongs and not of objects class .
Here the object does not get completely destroyed. For this reson we require virtual destructor.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions