next up previous contents index
Next: Const parameters Up: Using functions and procedures Previous: Using functions and procedures

Function overloading

Function overloading simply means that you can define the same function more than once, but each time with a different set of arguments.

When the compiler encounters a function call, it will look at the function parameters to decide which od the defined function This can be useful if you want to define the same function for different types. For example, if the RTL, the Dec procedure is is defined 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 wil first search which function it should use. It therefore checks the parameters in your function call, and looks if there is a function definition which maches the specified parameter list. If the compiler finds such a function, a call is inserted to that function. If no such function is found, a compiler error is generated.



Michael Van Canneyt
Thu Sep 10 14:02:43 CEST 1998