[fpc-devel] Visibility of overloaded ancestor method from a child class
    Maxim Ganetsky 
    ganmax at narod.ru
       
    Fri Feb  7 14:23:11 CET 2025
    
    
  
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