Function overloading by return type?
has a very detailed answer on the rational on function overloading by return type, and from what I can see Delphi does not allow this, but are there any workarounds to overload a function based on different return type in Delphi?
The implicit and explicit conversion operators for records permit overloading by return type: namely, the type being converted to:
type
TFoo = record
class operator Implicit(const AFoo: TFoo): Integer;
class operator Implicit(const AFoo: TFoo): string;
end;
Depending on the context, using a value of type TFoo
will call the appropriate implicit conversion. If trying to use a value of type TFoo
as an argument to an overloaded routine that can take either Integer or string in that position, an overload error will occur:
test.pas(33) Error: E2251 Ambiguous overloaded call to 'Q'
+ Test.pas(19) Related method: procedure Q(Integer);
+ Test.pas(24) Related method: procedure Q(const string);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With