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
16
votes
2 answers

Error when creating bean with type java.io.File [Ambiguous constructor argument types]

I have the following spring bean configuration I'm getting the following…
cyber-monk
  • 5,470
  • 6
  • 33
  • 42
16
votes
2 answers

Why is implicit conversion not ambiguous for non-primitive types?

Given a simple class template with multiple implicit conversion functions (non-explicit constructor and conversion operator), as in the following example: template class Foo { private: T m_value; public: Foo(); Foo(const T&…
Cybran
  • 2,203
  • 2
  • 17
  • 34
15
votes
2 answers

.Net 4.0 System.Web.Security.MembershipProvider ambiguous reference?

I have recently upgraded my BlogEngine.Net installation to 1.6 and .Net 4.0, however, I did not build BlogEngine.Core when I performed the upgrade. However, when I try to build the BlogEngine.Core project now, the compile fails because it cannot…
wilk
  • 987
  • 8
  • 16
15
votes
6 answers

Avoiding implicit def ambiguity in Scala

I am trying to create an implicit conversion from any type (say, Int) to a String... An implicit conversion to String means RichString methods (like reverse) are not available. implicit def intToString(i: Int) = String.valueOf(i) 100.toCharArray //…
Synesso
  • 37,610
  • 35
  • 136
  • 207
14
votes
5 answers

How is the Java compiler able to distinguish between those two constructors/methods?

public class MyClass { private String string; private Object[] objects; // constructor 1 public MyClass(String string, Object... objects) { this.string = string; this.objects = objects; } // constructor 2 …
sp00m
  • 47,968
  • 31
  • 142
  • 252
13
votes
1 answer

Ambiguous use of 'dispatch_get_main_queue()'

How do I replace the following Swift code for iOS using the DispatchQueue class? This is old Swift 3 code that the newest Xcode won't convert to Swift 5. dispatch_async(dispatch_get_main_queue()) { () -> Void in // code } It is giving me an…
daniel
  • 1,446
  • 3
  • 29
  • 65
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
3 answers

typedef and template parameter with same name

Why is that case incorrect (it's logical) template struct Der: public Base { typedef int T; T val; }; , but that case is correct? struct Base { typedef int T; }; template struct Der: public Base { T…
Denis
  • 2,786
  • 1
  • 14
  • 29
12
votes
2 answers

Why can't GCC disambiguate multiple inherited functions (yet clang can)?

Possible Duplicate: Why do multiple-inherited functions with same name but different signatures not get treated as overloaded functions? This fails to compile in the indicated place with g++ 4.6.1: enum Ea { Ea0 }; enum Eb { Eb0 }; struct Sa {…
John Zwinck
  • 239,568
  • 38
  • 324
  • 436
12
votes
2 answers

How to disambiguate this construction in a templated conversion operator?

After being confused why my code gave me an ambiguity error on GCC but no errors on Clang, I simplified the code. It can be seen below. struct Foo { // Foo(Foo&&) = delete; // Foo(const Foo&) = delete; Foo(int*) {} }; struct Bar { …
Post Self
  • 1,471
  • 2
  • 14
  • 34
12
votes
3 answers

Java Bug with ambiguous methods using varargs?

I have a class with two methods like this: public class Dummy{ public void doIt(String arg1, File arg2, Writer... ctx){ // Do something very important... } public void doIt(String arg1, Writer... ctx){ // Do something else... } …
12
votes
1 answer

request for member `...' is ambiguous in g++

I'm getting the following compile error in one of my classes, using gcc 3.4.5 (mingw): src/ModelTester/CModelTesterGui.cpp:1308: error: request for member `addListener' is ambiguous include/utility/ISource.h:26: error: candidates are: void…
cheshirekow
  • 4,797
  • 6
  • 43
  • 47
11
votes
1 answer

Overloading member function among multiple base classes

Basically I want to have multiple member functions with same name, but different signature, spread in multiple base classes. Example: #include struct A { void print(int) { std::cout << "Got an int!" << std::endl; } }; struct B { …
11
votes
4 answers

Android O Preview findViewById compile error

I tried to test the Android O Developer Preview second phase. After the project was created, I just clicked build and run but I didn't have any success. Android default generated code below: Toolbar toolbar = (Toolbar)…
Kihu Kwon
  • 111
  • 1
  • 4
11
votes
2 answers

How to deal with an overload resolution ambiguity of functions with generics?

Consider this class with two functions, one with Int argument, the other with a generic one: class C { // ... operator fun f(index: Int): Pair = ... operator fun f(key: K): V = ... } When it is parameterized as C
hotkey
  • 140,743
  • 39
  • 371
  • 326
1
2
3
40 41