Martin Frb via fpc-devel <fpc-devel@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 >
_______________________________________________ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel