OOPortal OOPortal

Ad Hoc Polymorphism  «Prev  Next»
Lesson 7 Overloading functions
Objective Compiler picks the appropriate version of an overloaded function.

Overloading Functions in C++

Overloaded functions are an important addition in C++. The overloaded meaning is selected by matching the argument list of the function call to the argument list of the function declaration. The function argument list is called the signature. The return type is not a part of the signature, but the order of the arguments is crucial.
Consider the following overloaded function declarations:

void print(int i = 0);   //signature is int
void print(int i, double x);   //int, double
void print(double y, int i);   //double, int

print('A');   //converts and matches int
print(str[]);     //no match, wrong type
print(15, 9);     //ambiguous
print(15, 9.0);   //matches int, double
print();          //matches int by default