Function Overloading
Function overloading:
The procedure which allows multiple
functions to have same name but differ in number of parameters and types of
parameters.
In function overloading, function’s
argument list is called function signature.
Declaration and definition of function
overloading:
To overload a function name, any two
definition of the function must have
1.
Functions
have same name
2.
Functions
have different signature
Declaration
void display();
void display(int);
void display(float);
void display(int,float);
Definition:
void display()
{
cout<<”function
overloading”;
}
void display(int x)
{
cout<<x;
}
void display(float y)
{
cout<<y;
}
void display(int a,float b)
{
cout<<a<<b;
}
Advantages of function overloading:
Eliminating the use of different function
names for same operation
Helps to understand, debug and grasp easily
Easy to maintain the code
Comments
Post a Comment