Maciej Izak schrieb:

Following by current logic, this example should not compile:

------begin code------
TA = class
  procedure Foo;
end;

TB = class(TA)
  procedure Foo(A: Integer = 0); overload;
end;

var
  b: TB;
begin
  b := TB.Create;
b.Foo; // should raise Error: Can't determine which overloaded function to call
end;
------end code------

Delphi (XE) has no problem with this code, even if TA.Foo also is declared "overload", or both are declared Foo(). The static type (b:TB) determines which static method to call.


Returning to the example from bugtracker (http://bugs.freepascal.org/view.php?id=25607): FPC don't recognize at TB level that the TObject.Create was hidden on the TA level by
constructor Create(A: Integer = 0); virtual; overload;

Delphi here requires
 constructor Create(A: Integer = 0); overload; virtual;

Delphi seems to search for overloaded methods only in the same class. Otherwise an error "Previous declaration ... not marked 'overload'" would occur since TObject.Create was not marked 'overload'. Tested with declarations in the same class:
  constructor Create;
  constructor Create(A: integer);
where *both* must be marked 'overload'.

Only if there is no matching method in a class, the ancestors are searched as well. I.e. Delphi does not *hide* inherited methods, it only extends the search into ancestors *when required*, regardless of 'overload' directives.

DoDi

_______________________________________________
fpc-devel maillist  -  [email protected]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to