Questions tagged [ambiguous]

An ambiguous call is a situation in which the compiler cannot deduce which version of a function or method to use from the given parameter types. This tag should not be confused with the [ambiguity] tag.

An ambiguous call occurs when the parameters can be converted in many ways such that they fit 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.

612 questions
62
votes
1 answer

GCC can't differentiate between operator++() and operator++(int)

template struct Pre { CRTP & operator++(); }; template struct Post { CRTP operator++(int); }; struct Derived : Pre , Post {}; int main() { Derived d; d++; ++d; } I get…
jotik
  • 17,044
  • 13
  • 58
  • 123
60
votes
4 answers

Why does the number of elements in a initializer list cause an ambiguous call error?

Why are the first two calls to doSomething OK by the compiler, but using two elements in the list causes an ambiguous call? #include #include void doSomething(const std::vector& data) {} void doSomething(const…
koolbanana
  • 719
  • 5
  • 11
58
votes
1 answer

Ambiguous call when using LINQ extension method on DbSet

I am using a LINQ query on a DbSet: await _dbContext.Users.AnyAsync(u => u.Name == name); However, the compiler outputs the following error: Error CS0121: The call is ambiguous between the following methods or…
janw
  • 8,758
  • 11
  • 40
  • 62
46
votes
2 answers

Partial ordering of function templates - ambiguous call

Consider this piece of C++11 code: #include #include template void f(T, const char*) //#1 { std::cout << "f(T, const char*)\n"; } template void f(int, const char(&)[N]) //#2 { std::cout <<…
bogdan
  • 9,229
  • 2
  • 33
  • 48
29
votes
6 answers

The call is ambiguous between single method i.e extension method

I have an extension method like public static class Extension { public static string GetTLD(this string str) { var host = new System.Uri(str).Host; int index = host.LastIndexOf('.'), last = 3; while (index >= last -…
shashwat
  • 7,851
  • 9
  • 57
  • 90
22
votes
2 answers

PI constant is ambiguous

Consider following code: fn main() { let i = f32::consts::PI; } With following error: $ rustc --version rustc 1.0.0 (a59de37e9 2015-05-13) (built 2015-05-14) $ rustc - :2:13: 2:28 error: ambiguous associated type; specify the type using…
Kapichu
  • 3,346
  • 4
  • 19
  • 38
22
votes
4 answers

Specflow test step inheritance causes "Ambiguous step definitions"

I want to have the following test step class structure: [Binding] public class BaseStep { [Given(@"there is a customer")] public void GivenThereIsACustomer(Table table) { HandleCustomer(table); } protected virtual void…
wd113
  • 477
  • 1
  • 9
  • 18
22
votes
1 answer

call of overloaded is ambiguous, how to deal with that?

I really don't understand this, I thought that compiler first executes what is in braces and then gives the result to the most appropriate function. Here it looks like it gives the function an initializer list to deal with it... #include…
rsk82
  • 28,217
  • 50
  • 150
  • 240
20
votes
1 answer

Why does function overloading generate an ambiguous error in C++?

In the following code snippets, In function call f(1), 1 is a literal of type int and in first function void f(double d) argument type is double and second function void f(short int i) argument type is short int. Here 1 is an int type not a double…
Jayesh
  • 4,755
  • 9
  • 32
  • 62
19
votes
4 answers

Why is this C++ expression involving overloaded operators and implicit conversions ambiguous?

operator bool breaks the use of operator< in the following example. Can anyone explain why bool is just as relevant in the if (a < 0) expression as the specific operator, an whether there is a workaround? struct Foo { Foo() {} Foo(int x)…
jkj yuio
  • 2,543
  • 5
  • 32
  • 49
19
votes
1 answer

Ambiguous method in Java 8, why?

public static void main(String... args){ then(bar()); // Compilation Error } public static E bar() { return null; } public static void then(Throwable actual) { } public static void then(CharSequence actual) {…
MariuszS
  • 30,646
  • 12
  • 114
  • 155
19
votes
1 answer

Multi Threading, Task.Run Error 'The call is ambiguous between the following methods or properties'

When I try to build project the following error message is displayed. The call is ambiguous between the following methods or properties: 'System.Threading.Tasks.Task.Run(System.Action)' and 'System.Threading.Tasks.Task.Run(System.Func)' How…
Emre BEGEN
  • 577
  • 1
  • 7
  • 17
17
votes
7 answers

How to write a standard-like function that has high overload priority

In a generic function I use the following idiom, template void do_something(It1 first, It1 second, It2 d_first){ ... other stuff here... using std::copy; copy(first, second, d_first); } do_something is a generic…
alfC
  • 14,261
  • 4
  • 67
  • 118
17
votes
4 answers

Ambiguous call from static context in Java

The main method tries to access var, but results in ambiguous call. Why? Instance variable var in Base1 isn't accessible (visible?) from static context anyway. class Base1 { int var; } interface Base2 { public static final int var…
user3613844
  • 273
  • 2
  • 8
17
votes
2 answers

Why is there ambiguity between uint32_t and uint64_t when using size_t on Mac OS X?

Consider following example code: #include #include using namespace std; int f(uint32_t i) { return 1; } int f(uint64_t i) { return 2; } int main () { cout << sizeof(long unsigned) << '\n'; cout << sizeof(size_t) <<…
maxschlepzig
  • 35,645
  • 14
  • 145
  • 182
1
2 3
40 41