Questions tagged [ambiguous-call]

Ambiguous call is a situation, when compiler cannot deduce from the passed parameter types, which version of function or method shall it use.

Ambiguous call happens, when the parameters can be converted in many ways, such that they fit to more than one overload of a function. For example:

void f(float f)
{

}

void f(double d)
{

}

Passing an int value to this function will cause an ambiguous call compiler error, because int can be converted both to float and to double while the compiler is not able to choose the overloaded version of function uniquely.

102 questions
142
votes
1 answer

Avoiding an ambiguous match exception

I am invoking a static method Parse on a type via reflection because I do not know the type of the object at compile-time (I do know, however, it has a Parse method, taking a string). However, I am getting an ambiguous match exception, presumably…
Ben Aston
  • 53,718
  • 65
  • 205
  • 331
92
votes
3 answers

Why does the most negative int value cause an error about ambiguous function overloads?

I'm learning about function overloading in C++ and came across this: void display(int a) { cout << "int" << endl; } void display(unsigned a) { cout << "unsigned" << endl; } int main() { int i = -2147483648; cout << i << endl;…
infinite loop
  • 1,309
  • 9
  • 19
44
votes
2 answers

literal `0` being a valid candidate for int and const string& overloads causes ambiguous call

I fixed a bug recently. In the following code, one of the overloaded function was const and the other one was not. The issue will be fixed by making both functions const. My question is why compiler only complained about it when the parameter was…
Cong Ma
  • 1,241
  • 1
  • 11
  • 20
35
votes
3 answers

Java: selection between overloaded constructors

Per this question, Java will select the "most specific" option when trying to select between ambiguous overloaded constructors. In this example: public class Test{ private Test(Map map){ System.out.println("Map"); } private…
ewok
  • 20,148
  • 51
  • 149
  • 254
28
votes
4 answers

How do I fix an "ambiguous" function call?

I'm working on a C++ program for class, and my compiler is complaining about an "ambiguous" function call. I suspect that this is because there are several functions defined with different parameters. How can I tell the compiler which one I want?…
Moshe
  • 57,511
  • 78
  • 272
  • 425
26
votes
7 answers

How to resolve ambiguity when argument is null?

Compiling the following code will return The call is ambiguous between the following methods or properties error. How to resolve it since I can't explicitly convert null to any of those classes? static void Main(string[] args) { …
Poma
  • 8,174
  • 18
  • 82
  • 144
26
votes
3 answers

What happens when a class and a function have the same name?

#include using namespace std; struct test { test(){cout<<"class"<
Denis
  • 2,786
  • 1
  • 14
  • 29
21
votes
8 answers

"redundant cast to java.lang.Object" warning for necessary cast

Consider this Minimal, Reproducible Example : interface Code { static void main(String[] args) { symbol( String.valueOf( true ? 'a' : true ? 'b' : true ? 'c' : …
Tom Hawtin - tackline
  • 145,806
  • 30
  • 211
  • 305
13
votes
1 answer

Why has this C++ code an ambiguous method call only on Microsoft compiler?

I'm trying to compile a library on microsoft C++ compiler 14.1 (Visual Studio 2017) but I'm getting a strange error due to an ambiguous call to a class method. After some testing I isolated the following code snippet: #include struct…
13
votes
2 answers

Template function call ambiguity error

I am not familiar with templates. I've just started learning it. Why I am getting errors in following program? #include #include using std::cout; using std::string; template C min(C a,C b) { return a
Destructor
  • 14,123
  • 11
  • 61
  • 126
13
votes
5 answers

How to resolve ambiguous ZIP call between Enumerable and MoreLINQ?

I've ran into problem with extension method resolution. LINQ and MoreLINQ contain zip method, it was present in .NET since 4.0 version and was always in MoreLINQ library. But you can't use one of the implementation with nice-old extension method…
Ilya Ivanov
  • 23,148
  • 4
  • 64
  • 90
12
votes
3 answers

SpringBoot @RestController, Ambiguous mapping found

Hi I have a simple RestController in my Sample: @RestController public class PersonController { @RequestMapping(name = "/getName", method = GET) public String getName() { return "MyName"; } @RequestMapping(name =…
Juraj
  • 738
  • 2
  • 9
  • 26
11
votes
2 answers

Template parameter is ambiguous: could not deduce template argument

I'm doing some kind of wrapper that looks like this: #include template void Apply(void (T::*cb)(Value), T* obj, Value v) { (obj->*cb)(v); } class Foo { public: void MyFunc(const int& i) { …
10
votes
2 answers

Obviously ambiguous call does not cause a compilation error on GCC

I was surprised by the fact that GCC does not consider the call to foo() in the following program ambiguous: #include struct B1 { bool foo(bool) { return true; } }; struct B2 { bool foo(bool) { return false; } }; struct C : public B1,…
Andy Prowl
  • 124,023
  • 23
  • 387
  • 451
9
votes
2 answers

Ambiguous invocation caused by picking up two versions of System.Linq

I have the following code, which shows a squiggly red line under the lambda expression after .Any( because of an "ambiguous invocation" between System.Linq versions 3.5 and 4.0 - how do I force it to use a particular version? It compiles and runs…
greg84
  • 7,541
  • 3
  • 36
  • 45
1
2 3 4 5 6 7