Function Overloading Intro

Overloading a function means to write another function bearing the same name but with a different parameter list. Given the function:
int multipy(int x, int y)
{
    return x * y;
}
The following function overloads it:
double multipy(double x, double y)
{
    return x * y;
}
because it provides another definition of the function multiply with parameters of a different type. The overloaded function might also just differ in the number of parameters taken:
int multipy(int x, int y, int z)
{
    return x * y * z;
}
Two versions of the same function cannot differ only in that a parameter of the same type is called by-reference in one case and by-value in another:
// wrong example of overloading
void go(int x);
void go(int &x);


Example


#include <iostream>
using namespace std;

int multiply(int x, int y)
{
    return x * y;
}

double multiply(double x, double y)
{
    return x * y;
}

int multiply(int x, int y, int z)
{
    return x * y * z;
}

int main()
{
    cout << multiply(2, 3) << endl;     // will call the first version
    cout << multiply(2.3, 3.5) << endl; // will call the second
    cout << multiply(2, 3, 5) << endl;  // will call the third
}

Output

6
8.05
30