Why oh why can't I manipulate the order in which overloaded methods get selected...
Why oh why can't I manipulate the order in which overloaded methods get selected...
SomeClass.....
class function Compare(const Left, Right: Integer): Integer; overload; static; inline;
class function Compare(const Left, Right: T): integer; overload; static; inline;
The generic one always has preference :(
Changing it to:
class function Compare(const Left, Right: TRecWithCustomOperators): integer; overload; static; inline;
Fixes the issue, but then I get ambiguous overloaded calls on enums and the like.
Grr.
SomeClass
class function Compare(const Left, Right: Integer): Integer; overload; static; inline;
class function Compare(const Left, Right: T): integer; overload; static; inline;
The generic one always has preference :(
Changing it to:
class function Compare(const Left, Right: TRecWithCustomOperators): integer; overload; static; inline;
Fixes the issue, but then I get ambiguous overloaded calls on enums and the like.
Grr.
Because the generic is more specific?
ReplyDeletetype
TRec = record
class procedure Func(const x: integer); overload; static;
class procedure Func(const x: T); overload; static;
end;
{ TRec }
class procedure TRec.Func(const x: integer);
begin
WriteLn('plain');
end;
class procedure TRec.Func(const x: T);
begin
WriteLn('generic');
end;
begin
TRec.Func('foo'); // outputs generic
TRec.Func(42); // outputs plain
ReadLn;
end.
Perhaps explain a bit more about what you're trying to do here?
You can simply give methods different names.
ReplyDeleteDavid Heffernan That's what I settled on.
ReplyDelete