[fpc-pascal] Wrong constructor returning the right object
Mark Morgan Lloyd
markMLl.fpc-pascal at telemetry.co.uk
Sun Feb 23 17:03:05 CET 2014
Marco van de Voort wrote:
> In our previous episode, Mark Morgan Lloyd said:
>
> That logical, since the constructors are not an virtual; and override; pair.
>
>> I find that if I explicitly decorate TB5500BaseUnit.Create() as virtual
>> and TB5500SPOUnit.Create() as override then TB5500SPOUnit.Create() is
>> called correctly.
>
> That's the normal way.
>
>> I didn't think this was necessary,
>
> _why_ did you think this?
In part, because the documentation on method declarations at
http://www.freepascal.org/docs-html/ref/refsu25.html#x66-730005.5.1
explicitly allows a virtual method directive, but the documentation on
constructor declarations at
http://www.freepascal.org/docs-html/ref/refse28.html#x64-710005.4
explicitly does not allow it.
>> but on reflection I
>> assume that it's because u is declared as a TB5500BaseUnit: the
>> variable's compile-time rather than run-time class is being used for the
>> constructor unless explicitly overridden.
>
> In theory this kind of information could propagate in simple cases, but then
> behaviour would differ between cases where this information could be
> propagated (a deeper version called), and not (base version called).
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk
[Opinions above are the author's, not those of his employers or colleagues]
More information about the fpc-pascal
mailing list