Example & Tutorial understanding programming in easy ways.

What is the function overloading in C++?

Function overloading in C++
Function overloading is a feature in C++ where two or more functions can have the same name but different parameters.

Example-
int sum(int a,int b,int c)
{
}
int sum(int a, int b)
{
}
int sum(double a,double b)
{
}
-Above three function are of same name but have different type of parameter and different number of parameter, so above three function are the example of function overloading.

program:

#include< iostream>

using namespace std;
class r4r
{
public:
int sum(int a,int b, int c)
{
cout<<"Sum is: "<< a+b+c<< endl;
}
int sum(int a,int b)
{
cout<<"Sum is: "<< a+b<< endl;
}
int sum(double a,double b)
{
cout<<"Sum is: "<< a+b<< endl;
}
};

int main()
{
r4r obj;
obj.sum(2,3,4);
obj.sum(1,2);
obj.sum(3.2,4.1);
return 0;
}


output-

Sum is: 9
Sum is: 3
Sum is: 7.3




Read More →