Cpp - Function Function Overloading


In C++, more than one function can have the same name as long as there are differences in their arguments.

This practice is called function overloading.

The functions must have different data types for parameters, a different number of parameters, or both.

The return types for overloaded functions do not factor into whether they are different.

You can't overload function by making the return different, however.

Here are three prototypes for overloaded functions:

int store(int, int); 
int store(long, long); 
int store(long); 

The store() function is overloaded with three different parameter lists.

The first and second differ in the data types and the third differs in the number of parameters.

The function is called by the type of its parameter among the overloaded functions.

An overloaded function called average() could be used with these prototypes:

int average(int, int); 
long average(long, long); 
float average(float, float); 

Related Topics