What is virtual constructors/destructors?
Page 1 of 1
What is virtual constructors/destructors?
Virtual destructors:
The explicit destroying of object with the use of delete operator to a base class pointer to the object is performed by the destructor of the base-class is invoked on that object.
The above process can be simplified by declaring a virtual base class destructor.
All the derived class destructors are made virtual in spite of having the same name as the base class destructor. In case the object in the hierarchy is destroyed explicitly by using delete operator to the base class pointer to a derived object, the appropriate destructor will be invoked.
Virtual constructor:
A constructor of a class can not be virtual and if causes a syntax error.
Similar topics
» What are the restrictions apply to constructors and destructors?
» What are destructors?
» When do you call copy constructors?
» In what situations do you have to use initialization list rather than assignment in constructors.
» What is a virtual destructor? Explain the use of it.
» What are destructors?
» When do you call copy constructors?
» In what situations do you have to use initialization list rather than assignment in constructors.
» What is a virtual destructor? Explain the use of it.
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|