[fpc-devel] function overload ?

Michael Van Canneyt michael at freepascal.org
Mon Feb 3 09:28:56 CET 2014

On Mon, 3 Feb 2014, Gennadiy Poryev wrote:

> Hi!
> I had a dream :)
> Wouldn't it be nice if a function overload took care not only of formal 
> parameter list (per docs) but also of result type? So the following may work
> function My(const a : Integer) : AnsiString; overload;
> function My(const a : Integer) : WideString; overload;
> by substitution of the function depending on the expected type of the 
> expression it is being called from?

Expressions don't work that way in Pascal.
The types in the expression determine the result type, not the other way round, there is no 'expected type'. 
That implies that the type of each term in the expression must be known.
That in turn means that the compiler cannot decide which function to use based on result type alone.


More information about the fpc-devel mailing list