In c++ there is only virtual destructors, no constructors. Why?

Showing Answers 1 - 1 of 1 Answers

samiksc

  • Jan 19th, 2006
 

At the time of constructing the object the type is given as input (B *ptr = new D) here it is clearly known that D's constructor is to be called. However while destroying, delete ptr; does not make it clear whether to call B's destructor (looking at the type of pointer) or to call D's destructor (looking at the type of object). So a virtual destructor helps in this case to call D's destrcutor.

  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