[fpc-pascal] Overloaded functions
pascalX at piments.com
pascalX at piments.com
Sun Oct 29 02:19:04 CET 2017
On 28/10/17 23:54, Darius Blaszyk wrote:
> Thanks! This is in line with what I was suspecting. However, why in the
> world does the compiler not warn in this case. This should be at least
> happening I would suppose?
>
> Darius
>
> Vojtěch Čihák schreef op 28 okt '17:
>
>> Overloading means that you have functions with the same name but
>> different parameter (or param. list). You can have different return
>> type for each parameter but you can never have the same parameters.
>>
>> V.
>>
>> ______________________________________________________________
>> > Od: Darius Blaszyk <dhkblaszyk at zeelandnet.nl>
>> > Komu: FPC-Pascal users discussions <fpc-pascal at lists.freepascal.org>
>> > Datum: 28.10.2017 22:58
>> > Předmět: [fpc-pascal] Overloaded functions
>> >
>>
>> Hi,
>>
>> I have a problem with overloaded functions. I defined these functions:
>> function val_(name: string): string;
>> function val_(name: string): boolean;
>> function val_(name: string): integer;
>> function val_(name: string): double;
>>
>> var
>> res: boolean;
>> begin
>> res := val_(option_variable);
>> end;
>>
>> I get the following error: Error: Incompatible types: got
>> "ShortString" expected "Boolean". So for some reason the compiler is
>> looking at the first function. The mode is objfpc and I turned
>> ansistrings off. I tested by adding the overload modifier but without
>> result. What else could I try or do? Or is overloading only allowed
>> for different parameter lists?
>>
>> Rgds, Darius
>>
>>
Agreed. The following incorrect override compiles without any problems.
Since the second definition is inaccessible, it should probably get
rejected by the compiler, or at least create a warning.
function val_(name: string): string;
begin
end;
function val_(name: string): boolean;
begin
end;
More information about the fpc-pascal
mailing list