What is the need /use of function overloading

Hint FO is mechanism in which two functions r having same name with diff no. of arguments.

Showing Answers 1 - 15 of 15 Answers

susie

  • Nov 10th, 2005
 

Funtion over loading is yet another feature of polymorphism.Diff functions with the same function name but diff arguments are defined in a class.During compile time the appropriate function is called dep on the arguments passed.Eg:

 class area

{

int sq,l,b;

float r;

public:

draw()

{cout<<"no shape"};

float draw(float );

int draw(int );

int draw(int ,int ); 

};

float shape:: draw(float cir)

{

r=cir;

return(3.14*r*r);

};

int shape::draw(int sq)

{

 return(sq*sq);

};

int shape::draw(int l,int b)

{

l=(a+b);

return(2*l);

};

so dep on the arg passed we get the area of circle square or rectangle.

  Was this answer useful?  Yes

sudheeer

  • Nov 13th, 2005
 

in overloading we use same function in somany types.

  Was this answer useful?  Yes

maheboob

  • Nov 24th, 2005
 

in function overloading, the function has single name but when it called from main function by passing different types of agruments, then it behaves accroding to the passed from the function.

the function different actions based on arguments,hence it's called as function overloading.

the need is that

                        1. rewriting of the code is not required

                        2. memory is saved.

  Was this answer useful?  Yes

ankur

  • Feb 9th, 2006
 

c++ is object oriented,,and constructors create objects frojm dust,,to create objects in different ways,,we provide constructors with diff arguments,some time without arguments ..thus function overloading is must..AS SIMPLE AS THAT

  Was this answer useful?  Yes

priya

  • Mar 4th, 2006
 

by using function overloading we can perform different operations using same function name,but one main thing is that we have to pass different arguments for all the functions,so that we can perform polymorphism.

  Was this answer useful?  Yes

bappa

  • Jun 6th, 2006
 

return type of overloading function should be same....

  Was this answer useful?  Yes

PEEYUSH KUMAR

  • Apr 28th, 2016
 

Suppose there is one user who needs a function to Sum two no. and suppose the programmer built the function and named it as sum(), ok now the user once again came to the programmer and said I need another function to sum 3 no. now programmer can make a another function suppose sum3() to add three no. then there is a problem that user have to remember 2 function for the same thing i.e addition of numbers but if the programmer uses the concept of function overloading he can name the function as sum() and pass three arguments so now the user does not have to remember more than one function for performing sum.

Hope it helps

  Was this answer useful?  Yes

abhi

  • Jul 8th, 2017
 

Because it allows you to do multiple work with same function call.

  Was this answer useful?  Yes

thash

  • Feb 10th, 2018
 

Two or more function can have same name but different from types or number of argument.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions