Function overloading simply means that the same function is de ned more than once, but each time with a di erent formal parameter list. The parameter lists must di er at least in one of its elements type. When the compiler encounters a function call, it will look at the function parameters to decide which one of the de ned functions it should call. This can be useful when the same function must be de ned for di erent types. For example, in the RTL, the Dec procedure could be de ned as:
...
Dec(Var I : Longint;decrement : Longint); Dec(Var I : Longint); Dec(Var I : Byte;decrement : Longint); Dec(Var I : Byte); ... |
When the compiler encounters a call to the Dec function, it will rst search which function it should use. It therefore checks the parameters in a function call, and looks if there is a function de nition which matches the speci ed parameter list. If the compiler nds such a function, a call is inserted to that function. If no such function is found, a compiler error is generated.
functions that have a cdecl modi er cannot be overloaded. (Technically, because this modi er prevents the mangling of the function name by the compiler).
Prior to version 1.9 of the compiler, the overloaded functions needed to be in the same unit. Now the compiler will continue searching in other units if it doesn't nd a matching version of an overloaded function in one unit.
The compiler accepts the presence of the overload modi er as in Delphi, but it is not required, unless in Delphi mode.