Google

Friday, March 14, 2008

CONSTRUCTOR CAN NOT BE VIRTUAL WHILE DESTRUCTOR CAN BE.

A constructor is a special member function whose task is to initialize the object.
In particular, "virtual" allows us to call a function knowing only an interfaces and not the exact type of the object. To create an object you need complete information. In particular, you need to know the exact type of what you want to create. Consequently, a "call to a constructor" cannot be virtual.

destructor is used to destroy the objects that have been created by a constructor
It is possible for the destructor to be virtual because the object already knows what type it is(whereas it doesn't during construction). and once the object has been created,its VPTR is initialized, so virtual function call can take place.

No comments: