Function overloading


A function is distinguishable from other functions not only by its name but also by the number and type of its arguments. The functions
int insert( int );
int insert( float );
int insert( int, int );
are all distinct and are said to be overloaded.
Operators (+,-,*,/,+=,++...) are functions. The addition operators in the statements
Vector2 c3 = c1 + c2;
int c3 = c1 + c2;
are distinct. The statements are equivalent to
Vector2 c3 = operator+( c1, c2 );
int c3 = operator+( c1, c2 );
The operator+ notation is usually only used in the implementation of the operator.
Why overloading? Improves readability by reducing namespace pollution (beware extremes!). Makes the language extensible. Used in inheritance and abstraction.
Note: The linker can distinguish overloaded functions because the compiler generates a symbol which encodes both the function name and the argument type information.