2. One of the more powerful features for code
readability is that of overloading.
Function overloading is the availability of
various functions within a class that differ
from each other in function signature i.e.
various functions share same name with
different parameter types or number of
parameters.
4. We use function overloading/method
overloading for the purpose of:
1. Compile time binding
2. Better Consistency
3. Better Readability
5. In this type of overloading we define two or
more functions with same two or more
function with same name and same
number of parameters, but the type of
parameter is different. For example in this
program,we have two sum() function, first
one gets two integer arguments and
second one gets two double arguments.
6. int sum(int x, int y)
{
cout<<x+y;
}
double sum(double x,
double y)
{
cout<<x+y;
}
int main()
{
sum(10,20);
sum(10.5,20.5);
}
7. Overloaded functions are distinguished by
their signatures.
A signature is a combination of function’s
name and its parameter types.
The compiler uses only parameter list to
distinguish between functions of same
name.
8. 1) Each overloaded function must differ either
by the number of its formal parameters or
their data types.
2) The return type of overloaded functions may
not be the same data type.
3) The default arguments of overloaded
functions are not considered by the c++
compiler as part of the parameter list.
4) Do not use the same function name for two
unrelated functions improper declarations
leading to conflict in a function call
statement.
9. void fun (char a, int times)
{
for (int i=1; i<=times; i++)
cout<<a;
}
Void fun (char a=“*” ,int times)
{
for(int i=1; i<=times; i++)
cout<<3;
}
Void fun (int times)
{
for(int i=1;i<=times; i++)
cout<<“@”;
}
Void main()
{
fun(‘+’ , 60);
fun(60);
}