answersLogoWhite

0


Best Answer

If the function names were not the same then they would not be overloads they'd just be ordinary functions. In reality, there is nothing special about overloads; they are treated just as if they had completely unique names. The compiler uses the name of a function in conjunction with the number and type of arguments passed to it by the caller to determine which function to actually call, whether the function is an overload or not. If no matching signature can be found, or there are two or more overloaded functions with the same signature, the compiler will alert you to the ambiguity. Note that the return type is not considered part of the function signature, hence overloads cannot differ by return type alone. If you need the same signature but a different return type, then you cannot use an overload, you must use a different function name in order to differentiate them.

The reason we use overloads rather than separate function names is merely one of convenience. If overloads were not permitted, then we'd be forced to use unique names for every function, even if the implementations were exactly the same and the only difference was in the type of argument being passed. That, in turn, would mean we could not use template functions (which allow the compiler to generate overloads for us), and we'd then be forced to write and maintain duplicate code ourselves.

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why in function overloading name of function is same?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Rules for function overloading?

It's a way by which you use define the same function for different input types. For example, think about the the operator "+" which in java works for adding integers, floating point numbers and even string concatenation. The way such functionality is achieved is by overloading.


What is function overloading in c language of computer?

There is no such thing as function overloading in C; that is a feature of C++. Function overloading allows us to provide two or more implementations of the same function. Typically, we use function overloading so that the same function can cater for different types. For instance, we might provide one implementation that is optimised to handle an integer argument while another is optimised to handle a real argument. We can also use function overloading to provide a common implementation of a function which can then be invoked by overloads that handle the low-level type conversions.


How operator overloading differ from function overloading?

Function overloading is multiple definition with different signatures(the parameters should be different) for the same function. The parameter list have to be different in each definition. The compiler will not accept if the return type alone is changed. Operator overloading is defining a function for a particular operator. The operator loading function can not be overloaded through function overloading.


Is constructor overloading same as method overloading.yes or no. explain?

yes,because in constructor overloading constructor have same and different parameter list. In method overloading method have same name and different parameter list.


What is method overloading and constructor overloading explain with?

method overriding :method overriding means redefine methods in sub classes they already defined in the Super classes.method overloading : It means methods with the same name but with a different signature exist in one class

Related questions

define function overloading?

Defining several functions with the same name with unique list of parameters is called as function overloading.


Rules for function overloading?

It's a way by which you use define the same function for different input types. For example, think about the the operator "+" which in java works for adding integers, floating point numbers and even string concatenation. The way such functionality is achieved is by overloading.


What is function overloading in c language of computer?

There is no such thing as function overloading in C; that is a feature of C++. Function overloading allows us to provide two or more implementations of the same function. Typically, we use function overloading so that the same function can cater for different types. For instance, we might provide one implementation that is optimised to handle an integer argument while another is optimised to handle a real argument. We can also use function overloading to provide a common implementation of a function which can then be invoked by overloads that handle the low-level type conversions.


How operator overloading differ from function overloading?

Function overloading is multiple definition with different signatures(the parameters should be different) for the same function. The parameter list have to be different in each definition. The compiler will not accept if the return type alone is changed. Operator overloading is defining a function for a particular operator. The operator loading function can not be overloaded through function overloading.


Is constructor overloading same as method overloading.yes or no. explain?

yes,because in constructor overloading constructor have same and different parameter list. In method overloading method have same name and different parameter list.


How the compiler compiles overloaded method?

method overloading occurs when we use two functions or more with the same name.In function overloading compiler detect which method is call actually throw the parameters passed to the methods.In function overloading parameters of functions are different.


What is the c plus plus program to calculate the area of a circle using function overloading?

Function overloading is used when you want to re-use the same function name with different argument types or a different number of arguments. Calculating the area of a circle isn't the sort of function that requires overloading since the only argument you need is the radius. double area_of_circle (const double radius) { const double pi=4*atan(1); return pi*radius*radius; }


What is the difference between over-loading and over-riding in cpp?

Overloading and overriding do similar things but they are distinct. When you override a function, you are providing a new implementation of a function that was inherited from a base class. The signature of an override must be covariant with the base class signature. Overloading means to create several functions with the same name within the same namespace but with different signatures.


Is it possible to do operator overloading in c?

No. Operator and/or function overloading is only a C++ thing.


What is method overloading and constructor overloading explain with?

method overriding :method overriding means redefine methods in sub classes they already defined in the Super classes.method overloading : It means methods with the same name but with a different signature exist in one class


What is the use of overloading in java?

method overloading is the primary way polymorphism is implemented in JavaOverloading methodsoverloaded methods: appear in the same class or a subclasshave the same name but,have different parameter lists, and,can have different return types


What is function overloading?

FUNCTION OVERLOADING:- when we define two functions with same name,in same class(may be) distinguished by their signatures- resolved at compile time- same method bt different parameters in each of themFUNCTION OVERRIDING:- when we redifine a function which is already defined in parent class- resolved at run time- changing the existing method