Showing posts with label Function Overloading. Show all posts
Showing posts with label Function Overloading. Show all posts

Monday, 30 April 2012

Program Of Function Overloading In C++

#include<iostream.h>
#include<conio.h>
class add
{
private:
int a,b;
public:
{
a=10;
b=20;
}
{
a= x;
b=x;
}
{
a=x;
b=y;
}
{
int c;
c=a+b;
cout<<"\n NAswer="<<c;
}

}
main()
{
add a1,a2,a3;
clrscr();
a1.getdata();
a2.getdata(5);
a3.getdata(5,6);
a1.display();
a2.display();
a3.display();
 getch();

}
-----------------------------------------------
Define Function Overloading

C++ permits the use of two function with the same 

name. However such functions essentially have 

different argument list. The difference can be in 

terms of number or type of arguments or both.

This process of using two or more functions with the

 same name but differing in the signature is called

 function overloading.

But overloading of functions with different return 

types are not allowed.


In overloaded functions , the function call 

determines which function definition will be

 executed.

The biggest advantage of overloading is that it helps

 us to perform same operations on different 

data types without  having the need to use separate

 names for each version.