[fpc-pascal] why constructor of TObject is NOT virtual but destructor is?
Marco van de Voort
marcov at stack.nl
Mon May 5 15:57:01 CEST 2014
In our previous episode, Xiangrong Fang said:
> I would like to know the benefit of making constructor / destructor
> virtual. As described here:
>
> http://c2.com/cgi/wiki?VirtualConstructor
>
> The benefit of virtual constructor seems related to "class reference". As
> far as I understand, it is related to how LCL works, like:
>
> CreateComponent(AComponent: TComponentClass);
>
> My questions are:
>
> 1) if the above understanding is correct AND COMPLETE, why the constructor
> of TObject is not virtual? What problem will appear IF we make it virtual?
> 2) What is the purpose of making destructor of TObject virtual?
I think you are thinking in the right direction, parameters is the reason.
This means that a framework that wants two or differently typed parameters
to the constructor can introduce its own deepest level constructor.
More information about the fpc-pascal
mailing list