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

`long` and `double` are same when converting from `int ` by compiler

I was studying function overloading in c++, and I saw an ambiguous condition, in the program, long add(long a){ long b = a; return b; } double add(double a){ double b = a; return b; } int main(){ int x; x = add(10); …
Siraj Alam
  • 9,217
  • 9
  • 53
  • 65
4
votes
2 answers

Resolving virtual method overloads across base classes

Visual Studio 2013. Given: class base_1 { public: virtual void foo(int) = 0; }; class base_2 { public: virtual void foo(int, double) = 0; }; class join_1_2 : public virtual base_1, public virtual base_2 {}; I have a sink: void…
Matthew Reddington
  • 1,409
  • 3
  • 13
  • 24
4
votes
1 answer

How this function call is ambiguous in C++?

Consider following program: (See live demo here http://ideone.com/7VHdoU ) #include void fun(int*)=delete; void fun(double)=delete; void fun(char)=delete; void fun(unsigned)=delete; void fun(float)=delete; void fun(long int); int…
Destructor
  • 14,123
  • 11
  • 61
  • 126
4
votes
1 answer

(Lack of) Ambiguous Type When Using Read and Show in Haskell

I wrote a very simple Haskell program: main = print $ sum $ map read ["55", "99", "101"] Given my past experience, I expected to get an "ambiguous type" error, since the signature of sum $ map read [...] is (Read a, Num a) => a; Num is a class and…
Tanaki
  • 2,575
  • 6
  • 30
  • 41
4
votes
1 answer

Ambiguous operator<< selection

I have some code which, very much simplified, looks somewhat like this: #include #include namespace X { struct Foo {int x;}; struct Bar {int x;}; template
Svalorzen
  • 5,353
  • 3
  • 30
  • 54
3
votes
1 answer

How dangerous is AllowAmbiguousTypes when used with TypeApplications?

How dangerous is the AllowAmbiguousTypes extension when used with the TypeApplications extension? The GHC manual gives the following example of an ambiguous type: class C a f :: C a => Int f = 3 This fails to compile when not using…
illabout
  • 3,517
  • 1
  • 18
  • 39
3
votes
2 answers

Why following call is ambiguous?

The following call will fail because compiler expects method SetAll(PropertyInfo, int). var infos = GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); var setters = infos.Select(SetAll); // no overload matches delegate. private…
M.kazem Akhgary
  • 18,645
  • 8
  • 57
  • 118
3
votes
1 answer

C# Compiler complaining function is ambiguous with itself

Working in a C# WebApp project which I've inherited. I have a couple function definitions as so... public static DataTable ExecuteDT(this AppDBContext target, string sql, int timeoutSeconds = defaultTimeoutSeconds) { DbCommand cmd =…
eidylon
  • 7,068
  • 20
  • 75
  • 118
3
votes
1 answer

Query error with 2 ambiguous column names in SQL

I've been working with this Query for bit now and I'm having a hard time. I'm new to SQL and I can't figure our why I'm getting the error: SELECT customer_number, first_name_initial, last_name,serve_address_1, serve_address_2, serve_city,…
E. Peterson
  • 432
  • 2
  • 6
  • 15
3
votes
1 answer

How is a method taking const char* as argument a near match to a method taking const int&?

The following code throws compiler error when I compile it. template inline T const& max (T const& a, T const& b) { return a < b ? b : a; } // maximum of two C-strings (call-by-value) inline char const* max (char const* a, char…
sajas
  • 1,599
  • 1
  • 17
  • 39
3
votes
2 answers

C++ template and ambiguous function call

Some code I have no control over has a number of overloaded functions which accepts different types i.e. setValue(int) setValue(std::string) setValue(bool) And I have a template function which would idealy take any one of these types and pass it on…
user2675345
  • 531
  • 3
  • 12
3
votes
2 answers

C++ templates and ambiguity problem

I have a subset of a pointer class that look like: template struct Pointer { Pointer(); Pointer(T *const x); Pointer(const Pointer &x); template Pointer(const Pointer &x); operator T *()…
cvb
  • 4,321
  • 6
  • 26
  • 19
3
votes
6 answers

Java ambiguous type for method?

EDIT: This turned out not be a problem with the code at all, but with a bug in the Groovy Eclipse plugin (http://jira.codehaus.org/browse/GRECLIPSE-373) Eclipse is giving me a weird error message about ambiguous types in a Java program and I really…
Jeff Storey
  • 56,312
  • 72
  • 233
  • 406
3
votes
2 answers

Non-obtrusive way of getting around an argument dependent lookup ambiguity

Here's my case: I am trying to use a library that has a type Foo::a, and specifies a Foo::swap as well. Another library that I am consuming has a std::vector instantiation. I am trying to compile this on Windows using Visual Studio 11.0 and…
user2184879
  • 183
  • 6
3
votes
3 answers

Generic parameter inference and ambiguous function call - is there a workaround?

Possible Duplicate: Ambiguous call between two C# extension generic methods one where T:class and other where T:struct I've this two functions : public static Degrees Convert(this TInput input) where TInput : NumericValue,…
Nicolas Voron
  • 2,916
  • 1
  • 21
  • 35