Hello all!...
I went through few study material, and understood
why virtual constructor can't be there...
What i understood about constructor's is as follows:..
Constructors initializes the object and hence also the
virtual pointer..but if constructor is virtual...it will not be possible to
invoke constructor on the first place..since there won't be virtual pointer
initialized, which is job of constructor...
well, then i can't understand why virtual destructor's are need then....?
please explain me or help me with online articles or links to
find this "Why?" questions solution...!
if you have a hierarchy of parent/child classes, you need to
call first the destructor of the lowest child class, then of its parent,
then of the parent of that class, etc., until you reach the root of
the hierarchy.
If you have a pointer to an instance of the root class, or
any other class that is not the lowest level child class,
the virtual destructor will make sure that the correct
sequence of destructors is called, namely, starting with
the most derived class moving up until the root class destructor
is called as the last of all.
If the destructor would not be virtual, you would not properly
delete any stuff that was allocated by the lower level child classes,
so you end up with corrupted stacks or memory leaks.