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
6
votes
1 answer

Why does not std::nullptr_t work with std::cout in C++?

I learned about std::nullptr_t that is the type of the null pointer literal, nullptr. Then I made small program : #include int main() { std::nullptr_t n1; std::cout<
user7620837
6
votes
1 answer

Conversion and move ctor leads to ambiguous call for Clang and GCC 4.9.2

I am a bit stumped by the following conversion problem in C++11. Given this code: #include struct State { State(State const& state) = default; State(State&& state) = default; State() = default; int x; }; template
Claudius
  • 550
  • 3
  • 14
6
votes
1 answer

After Swift 3 conversion, I can't get rid of error: "Ambiguous use of 'indexOfObject(passingTest:)'"

I'm using NSArray's indexesOfObjects(passingTest:), but after I converted my code to Swift 3 I get the error: "Ambiguous use of 'indexOfObject(passingTest:)'". My code below worked fine with Swift 2.3. let indexesOfBubbleConstraints =…
Stephan
  • 881
  • 9
  • 24
6
votes
4 answers

Width and Horizontal Position Are Ambiguous

it seems I have created a simple Image view with the following constraints: Align Center X to: Superview Align Center Y to: Superview Top Space to: Top Layout Guide Bottom Space to: Bottom Layout Guide And I have the Width and Horizontal Position…
Glyphs
  • 97
  • 1
  • 1
  • 7
6
votes
1 answer

Ambiguous C# method call with delegates

In my application, I have code similar to following: class Program { static void Main(string[] args) { Method(uri => Task.FromResult(uri)); } static void Method(Func transformer) { …
richzilla
  • 40,440
  • 14
  • 56
  • 86
6
votes
1 answer

Using float gives "call to overloaded function is ambiguous" error

I'm overloading the function add(), but when I used the float datatype it is showing an error. However, when I change it to double, then it's working fine. Why is float causing the error? Code is: #include using namespace std; class…
Asif Mushtaq
  • 3,658
  • 4
  • 44
  • 80
6
votes
2 answers

Ambiguous call between overloads of two-way implicit castable types when a derived type of one is passed as parameter

(Trying to find a title that sums up a problem can be a very daunting task!) I have the following classes with some overloaded methods that produce a call ambiguity compiler error: public class MyClass { public static void…
GDS
  • 1,337
  • 12
  • 18
6
votes
2 answers

C++: disambiguate this code at compile time?

i tried to find a way to disambiguate this code (at compile time) (since two days :-) -> get_value is ambugiuous. #include template struct type2type {}; template struct BASE { static constexpr int…
Monotomy
  • 554
  • 1
  • 6
  • 24
6
votes
3 answers

The call is ambiguous between the following methods or properties C#

While compiling my program (I compile it from MonoDevelop IDE) I receive an error: Error CS0121: The call is ambiguous between the following methods or properties: System.Threading.Thread.Thread(System.Threading.ThreadStart)' and …
Vlad
  • 65
  • 1
  • 4
6
votes
1 answer

Call to function is ambiguous in C++. Candidate functions are the Prototype and the function itself

I am working through Stanford CS106B C++ assignments and I have a 'semantic issue' with an assignment. It seems as if the compiler cannot deduce whether the call is to a function or to the prototype of the function. I don't understand why a call…
Mehul
  • 129
  • 1
  • 1
  • 7
6
votes
2 answers

How to access a member of a nested class, that is hidden by a member of the outer class

I have a source-code generator that risks generating the following type of code (just an example): public class Outer { public static final Object Inner = new Object(); public static class Inner { public static final Object Help =…
Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
5
votes
1 answer

Ambiguous call when overloaded methods take reverse iterators in arguments

I'm trying to write an overloaded method that returns non-const result only when both the object on which it is called is non-const and iterator passed in the argument is non-const. (Think of it like the standard methods begin() and begin() const…
Piotr Siupa
  • 3,929
  • 2
  • 29
  • 65
5
votes
1 answer

How the code run when exist override ambigous function?

I can not fully understand the code result when exist override ambigous function. I have a libray libMy, which contains two class A and B. The code shows as follows // A.h #ifndef included_A_h #define included_A_h class A { public: void…
Xu Hui
  • 1,213
  • 1
  • 11
  • 24
5
votes
1 answer

Why is no compile-time error when calling an ambiguous ctor?

#include #include int main() { auto v1 = std::vector(std::size_t{8}); std::cout << v1.size() << std::endl; auto v2 = std::vector{std::size_t{8}}; std::cout << v2.size() <<…
xmllmx
  • 39,765
  • 26
  • 162
  • 323
5
votes
1 answer

Out of class definition of member function template in the presence of a member function of the same name - compiler divergence

Consider this example of a class template containing a member function and a member function template both of which are named f followed by an attempt to define and specialize the member function template: template struct A { void…
0x5f3759df
  • 2,349
  • 1
  • 20
  • 25