14. Explain Function overloading.
Answers
Explanation:
In some programming languages, function overloading or method overloading is the ability to create multiple functions of the same name with different implementations. Calls to an overloaded function will run a specific implementation of that function appropriate to the context of the call, allowing one function call to perform different tasks depending on context.
For example, doTask() and doTask(object O) are overloaded functions. To call the latter, an object must be passed as a parameter, whereas the former does not require a parameter, and is called with an empty parameter field. A common error would be to assign a default value to the object in the second function, which would result in an ambiguous call error, as the compiler wouldn't know which of the two methods to use.
Another appropriate example would be a Print(object O) function. In this case one might like the method to be different when printing, for example, text or pictures. The two different functions may be overloaded as Print(text_object T); Print(image_object P). If we write the overloaded print functions for all objects our program will "print", we never have to worry about the type of the object, and the correct function call again, the call is always: Print(something).
Answer:
Explanation:
Function overloading is a feature of c++ where two or more functions can have the same name but different parameters.
Function refers to a segment that groups code to perform a specific task.
Two Function can have same name if number and/or type of argument passed are different.
// int test() { }
int test (int a) { }
float test(double a) { }
int test(int a , double b) { } //
Here all 4 function are overloaded because argument () passed to these function are different.
Notice that the return type of all these 4 function are not same . Overloaded functions are not same . Overloaded function may or may not have different return type but it should have different argument().