[fpc-devel] virtual override with diff in default ?
Sven Barth
pascaldragon at googlemail.com
Tue Oct 22 23:38:07 CEST 2024
Martin Frb via fpc-devel <fpc-devel at lists.freepascal.org> schrieb am Di.,
22. Okt. 2024, 23:28:
> Is the below meant to be allowed?
> It compiles, it also compiles if you have no default in the base, but a
> default in the sub class.
>
> type
> TFoo = class
> procedure Bar (const Item: String; AnObject: TObject = nil); virtual;
> end;
> TFoo2 = class(TFoo)
> procedure Bar (const Item: String; AnObject: TObject); override;
> end;
>
>
> It even works with both having a diff default.
>
> TFoo = class
> procedure Bar (const Item: String; AnObject: integer = 1); virtual;
> end;
> TFoo2 = class(TFoo)
> procedure Bar (const Item: String; AnObject: integer=2); override;
> end;
>
A default value is not part of the signature. In the end the behavior will
depend upon the concrete instance used: if youe variable is declared as
TFoo then that default value will be used. If it's the first TFoo2 then the
parameter is not optional and for the second TFoo2 the value passed in will
be 2.
Regards,
Sven
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20241022/883e8e3d/attachment.htm>
More information about the fpc-devel
mailing list