How Can A Call To An Overloaded Function Be Ambiguous?

Originally posted on June 18, 2022 @ 12:15 pm

Answer. A call to an overloaded function can be ambiguous in one of the following two ways: 1) The arguments mentioned in the function where it is called do not match the arguments at the point where the function is called. 2) The same function is defined more than one time in the same program…….

What is Function Overloading?

Function Overloading is when two or more functions have the same name but are different in how many arguments they take or what kind of data they take. Function overloading is the process of giving the same function name to different data items that do similar kinds of work.

Function Overloading is also known as Compile time polymorphism.

For Example:

// How can a call to an overloaded function be ambiguous
int foo() { }
int foo(int a) { }
float foo(double a) { }
int foo(int a, double b) { }

In the above example, test functions vary in either the number of arguments or the type of arguments it takes. This is function overloading.

// How can a call to an overloaded function be ambiguous

int foo(int a) { }
float foo(int a) { }

So, how can a call to a function that does too much be unclear? In function overloading, there are times when the compiler can’t decide between two functions that have been correctly overloaded. People say that this situation is not clear.

Statements that aren’t clear cause errors, and programs that have ambiguous statements won’t compile. The main cause of ambiguity is automatic type conversions.


Parag Banerjee is an experienced Search Engine Optimizer. He has a wide knowledge of Google Updates, Analytics, and many others. He studied Computer Application from Techno India.

Articles: 317