Function-Overloading in CPlusPlus

Function-Overloading in CPlusPlus

When two or more than two functions are declared in a program which are having the same name but different arguments/ parameters; we say function-overloading has occurred.

In function-overloading the difference of the functions can be in the number of arguments of in the types of arguments.

A function is a piece of code that is use to accomplish a specific task. The very common syntax for a function is as below;

In case the name of more than one function in a program is the same. While the number of parameters in the functions are different or their type is different, we say function-overloading has happened. The return type of the function can be the same or different.

For Example; the following functions are overloaded if they are declared all in the same program.

Note: It is important to remember that a function cannot be overloaded by its return type. For function-overloading parameters should be different in type or number.

The following code will produce an error.

Why? Because the return types of the functions cannot be counted as function-overloading.

See Also: [button link=”” size=”default” icon=”fa-plus” side=”left” target=”” color=”05b735″ textcolor=”ffffff”]Functions in CPlusPlus[/button]

Below you will find a complete program that has demonstrated the concept of function-overloading with the function volume ();


In the above example; the function volume () is overloaded. The first function accepts one parameter, the second one accepts two parameters and the third one accepts three parameters. While the number of parameters/ arguments are different in the functions above and the name of the functions are the same; we say function-overloading has occurred.


Function-OverLoading Output

Please feel free to put your comments below and suggest us what other topics would you like to cover in the upcoming articles.

Bahonar Javid

* Computer Application Student * Co-Founder of * Love to code and Learn new languages * Enjoy playing football

Related Posts