[fpc-devel] Visibility of overloaded ancestor method from a child class

Maxim Ganetsky ganmax at narod.ru
Fri Feb 7 20:42:03 CET 2025


07.02.2025 22:27, Michał Gawrycki пишет:
> From documentation:
>
> If the overload keyword is not present, then all overloaded versions 
> must reside in the same unit, and if it concerns methods part of a 
> class, they must be in the same class, i. e. the compiler will not 
> look for overloaded methods in parent classes if the overload keyword 
> was not specified.
>
> https://www.freepascal.org/docs-html/ref/refse96.html
Thanks, guys.

> Regards, Michał.
>
> W dniu 2025-02-07 o 14:23, Maxim Ganetsky via fpc-devel pisze:
>> Hello.
>>
>> The following program does not compile, because overloaded AddItem(s: 
>> string) method in ancestor is not visible from child class. Is it 
>> normal?
>>
>> program Test;
>> {$MODE OBJFPC}
>> type
>>    TBase = class
>>    public
>>      procedure AddItem(s: string; i: integer); virtual;
>>      procedure AddItem(s: string);
>>    end;
>>    TDesc = class(TBase)
>>    public
>>      procedure AddItem(s: string; i: integer); override;
>>    end;
>>
>> procedure TDesc.AddItem(s: string; i: integer);
>> begin
>>    writeln('TDesc(s,a) ', s, ' ', i);
>> end;
>> procedure TBase.AddItem(s: string; i: integer);
>> begin
>>    writeln('TBase(s,a) ', s, ' ', i);
>> end;
>> procedure TBase.AddItem(s: string);
>> begin
>>    AddItem(s, 123);
>> end;
>>
>> var
>>    lBase: TBase;
>>    lDesc: TDesc;
>> begin
>>    lBase := TBase.Create;
>>    lDesc := TDesc.Create;
>>    lBase.AddItem('test'); // OK
>>    lDesc.AddItem('test'); // Error: Wrong number of parameters 
>> specified for call to "AddItem"
>>    readln;
>> end.
>>
>

-- 
Best regards,
  Maxim Ganetsky                  mailto:ganmax at narod.ru



More information about the fpc-devel mailing list