Function overloading in c++ code:

Function overloading is very important in c++. In the function overloading, the name of both functions same but the parameters in the function are different. You can understand the use of function overloading by watching the code below.

Code without Prototype:


#include <iostream>
using namespace std;
void fun(int x)
{
                cout<<"Here printing integer number "<<x<<endl;
}
void fun(float x)
{
                cout<<"Here printing float number "<<x<<endl;
}
int main()
{
                int a=44;
                float b=66.89;
                fun(a);
                fun(b);
}

Code with Prototype:


#include <iostream>
using namespace std;
void fun(int x);
void fun(float x);
int main()
{
                int a=44;
                float b=66.89;
                fun(a);
                fun(b);
}
void fun(int x)
{
                cout<<"Here printing integer number "<<x<<endl;
}
void fun(float x)
{
                cout<<"Here printing float number "<<x<<endl;
}

Output:


Here printing integer number 44
Here printing float number 66.89

The output will be same in both codes. Hope you will understand the use of function overloading in c++.


Click here for watching the video of that code

avatar
AUTHOR: Muhammad Abbas
I am Software Engineer.

0 Comments