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

C++11 constructor overload resolution and initialiser_lists: clang++ and g++ disagree

I have a small piece of C++11 code which g++ (4.7 or 4.8) refuses to compile claiming that the call to constructor for B2 b2a(x, {P(y)}) is ambiguous. Clang++ is happy with that code, but refuses to compile B2 b2b(x, {{P(y)}}) which g++ is perfectly…
Phil Armstrong
  • 1,796
  • 1
  • 10
  • 17
8
votes
2 answers

Ambiguous call when a method has overloads for IDictionary and IDictionary

When a method has two overloads, one accepting IDictionary and another accepting IDictionary, passing new Dictionary() to it is considered ambigous. However, if the two overloads are changed to accept IEnumerable and…
Athari
  • 33,702
  • 16
  • 105
  • 146
7
votes
2 answers

Why does implementing this generic interface create an ambiguous reference?

Let's say I have the following: public interface Filter { public boolean accept(E obj); } and import java.io.File; import java.io.FilenameFilter; public abstract class CombiningFileFilter extends javax.swing.filechooser.FileFilter …
Jeffrey
  • 44,417
  • 8
  • 90
  • 141
7
votes
3 answers

c++ conversion operator overloading, enums, ints and chars

When I try to compile (with gcc 4.3.4) this code snippet: enum SimpleEnum { ONEVALUE }; void myFunc(int a) { } void myFunc(char ch) { } struct MyClass { operator int() const { return 0; }; operator SimpleEnum() const { return…
7
votes
4 answers

Java method overloading and varargs

I am trying to understand method overloading, and I have these methods. public void method(int a){ System.out.println("int a"); } //implementing interface method @Override public void method() { …
7
votes
2 answers

Multiple Inheritance Template Class

class messageA { }; class messageB { }; template class queue { public: virtual ~queue() {} void submit(T& x) {} }; class A : public queue, public queue { }; int main() { A aa; aa.submit(messageA()); …
Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875
7
votes
1 answer

Generic method overload ambiguous with nullable types

Say I have two generic, overloaded methods of the form: public string Do(T maybeValue, Func func) where T : class { if(maybeValue == null) return null; return func(maybeValue); } public string Do(T? maybeValue, Func
knittl
  • 246,190
  • 53
  • 318
  • 364
7
votes
1 answer

Ambiguous occurrence '=='

I'm just learning Haskell and still trying to figure out how things work. So I'm creating a list class that can hold a mixture of Int and Char. data Algebra = Empty | Nmbr Int Algebra | Smbl Char Algebra Then I try to make it an instance of…
7
votes
1 answer

ambiguous column name: error not working with tags

I have some code to display my recipes in order of their popularity as shown below. This is stored in my index file for the recipe view. <% @all_recipes.this_week.reorder("likes_count DESC").limit(10).each do |i| %> <%=link_to…
MikeHolford
  • 1,851
  • 2
  • 21
  • 32
7
votes
1 answer

Standard method for determining the arity and other traits of std::bind() result?

I've been pounding my head for a few days trying to figure out how to make a class have a nice clean public interface to perform registration of callback mechanisms. The callbacks can be C++11 lambdas, std::function,…
7
votes
10 answers

Ambiguous reference in WCF and client application

I've managed to reproduce one of the errors in a test project with a similar structure to my production code. It consists of three simple projects: Common (class library): namespace Common { public enum PrimaryColor { Red, …
CuriousBenjamin
  • 709
  • 1
  • 9
  • 26
6
votes
3 answers

Resolving CRTP function overload ambiguity

I have several functions that I would like to work for derived classes of a CRTP base class. The issue is that if I pass the derived classes into the free functions meant for the CRTP class, ambiguities arise. A minimal example to illustrate this is…
lightxbulb
  • 1,251
  • 12
  • 29
6
votes
2 answers

Template deduction complaints ambiguous candidates

I intend to implement the multiplication operator of my "Sparse Vector" and "Vector" classes. The following simplified code demo shows my problem The Vector class in Vector.hpp #pragma once template class Vector { public: Vector()…
Rubin
  • 332
  • 1
  • 10
6
votes
2 answers

Generic method not overriding similar generic method in superclass -> Which one is used?

Given this situation: public class Animal { public void genericMethod(T t){ System.out.println("Inside generic method on animal with parameter " + t.toString()); } } public class Cat extends Animal { public
DanielBK
  • 892
  • 8
  • 23
6
votes
1 answer

Is this local variable shadowing/hiding another normal or a bug in Visual Studio?

I've greatly simplified this question as the same problem arises in a simpler case: #include int height; int main() { std::cout << height; // Visual Studio debugger shows this value as -858993460 int height; } Seems a…
Zebrafish
  • 11,682
  • 3
  • 43
  • 119