Function Overloading/Method Overloading in C++.|Simple program on Overloading|

Overloading in C++ is considered as polymorphism . If function overloading or method overloading of functions, functions has same name but they have different parameter.To understand the function overloading see the program below.

#include
#include
int add();
int add(int a);
int add(int a,int b);
float add(float a,int b);
float add(int a,float b);
void main()
{
clrscr();
cout<<add()<<add(1)<<add(1,2)<<add(1.5f,2)<<add(1,.2f);
getch();
}
int add()
{
return 0;
}
int add(int a)
{
return a;
}
int add(int a,int b)
{
cout<<"\Intwala\n";
return a+b;
}
float add(float a,int b)
{
cout<<"\nFloatwala\n";
return a+b;
}
float add(int a,float b)
{
cout<<"\nUlta Floatwala\n";
return a+b;
}

If you will the program you can clearly understand the overloading. Same function but different parameters.

Leave a Reply