Function overloading in C++: C++ program for function overloading. Function overloading means two or more functions can have the same name but either the number of arguments or the data type of arguments has to be different. Return type has no role because function will return a value when it is called and at compile time compiler will not be able to determine which function to call. In the first example in our code we make two functions one for adding two integers and other for adding two floats but they have same name and in the second program we make two functions with identical names but pass them different number of arguments. Function overloading is also known as compile time polymorphism.
C++ programming code
In the above program, we have created two functions "add" for two different data types you can create more than two functions with same name according to requirement but making sure that compiler will be able to determine which one to call. For example you can create add function for integers, doubles and other data types in above program. In these functions you can see the code of functions is same except data type, C++ provides a solution to this problem we can create a single function for different data types which reduces code size which is via templates.
C++ programming code for function overloading
Output of program: