[fpc-devel] function overloading question
Bruce Bauman
bruce.bauman at andesaservices.com
Tue Sep 8 16:44:36 CEST 2009
Can an overloaded function differ only by the return type?
For example:
function ReturnSomething(i : integer) : integer;
begin
ReturnSomething := 1;
end;
function ReturnSomething(i : integer): real;
begin
ReturnSomething := 2.0;
end; { ReturnReal }
I get bizarre results when I try this. If I define the functions in this
order, and then call them as follows:
begin
i := ReturnSomething(3);
writeln('i = ', i);
r := ReturnSomething(4);
writeln('r = ', r);
end.
the first function is called in both cases.
If I reverse the order of the function declarations the program fails to
compile:
Incompatible types: got "Real" expected "SmallInt"
Should I expect this behavior?
I can file a more complete bug report if needed.
-- Bruce
CONFIDENTIALITY NOTICE: This e-mail is confidential and intended
solely for the use of the individual or entity to which it is addressed. If
you are not the intended recipient, be advised that you have received
this email in error and that any use, dissemination, forwarding, printing
or copying of this e-mail is strictly prohibited. If you received this e-mail
in error, please delete it from your computer and contact the sender.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20090908/16f353a7/attachment.html>
More information about the fpc-devel
mailing list