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

Why am I getting ambiguous call for the following functions?

Consider the following: template class testString { public: typedef T* iterator; void insert(iterator aPos, size_t numChars, T aChar); testString& insert(size_t aIndex, size_t numChars, T aChar); }; template
Samaursa
  • 16,527
  • 21
  • 89
  • 160
2
votes
1 answer

Combine capabilities of classes (mixins) with ambiguous calls

I was reading about the "mixin" technique in C++ but there is something I don't understand and seems to be a limitation in the language that prevents to do it generically because of ambiguities that the compiler (and the standard refuse to resolve,…
alfC
  • 14,261
  • 4
  • 67
  • 118
2
votes
1 answer

Ambiguous call for UseHttps extension method

In my ASP.NET Core 3.1 project I have the following configuration in Program.cs: using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using…
janw
  • 8,758
  • 11
  • 40
  • 62
2
votes
1 answer

Exact overload resolution procedure - why f(1) call against f(int... arg) and f(long... arg) is not ambiguous?

I feel that these are applicable: JLS 15.12.2.4. Phase 3: Identify Methods Applicable by Variable Arity Invocation JLS 15.12.2.5. Choosing the Most Specific Method But JLS language is so complex that I cannot understand the point. void…
Code Complete
  • 3,146
  • 1
  • 15
  • 38
2
votes
1 answer

Avoid spelling out type in artificially amgibuous overloaded function call

Minimal example program: #include void f(std::vector) {} // #1 void f(std::vector) {} // #2 int main() { f({ 1 }); } It would intuitively make sense for this to be a valid program: the call using overload #1 would be valid,…
user743382
2
votes
2 answers

C# Error in calendar after upgrading project .net target framework from 3.5 to 4.5

I have the below function of buildculture for calendar: private void buildCulture(string culture, string calendarType) { CultureInfo ci=null; try { if (string.IsNullOrEmpty(culture)) { ci =…
Coolguy
  • 2,225
  • 12
  • 54
  • 81
2
votes
2 answers

Is there way out of this ambiguity?

Consider this (rather) simple example: #include struct Out { int value; }; template decltype(auto) operator<<(Sink &&s, Out const &out) { return out.value > 0? s << out.value : s; } struct In { std::ostream…
bipll
  • 11,747
  • 1
  • 18
  • 32
2
votes
1 answer

Ambiguous column name when select a column to return value if column is available in table by Execute Dynamic SQL commands

I want to return a column value if column is available in table,if not, return a default value, then I face COLUMN_NAME ambiguous error when join two table SHAIN1 and RIREKI14. If select from only one table then query works ok but if I join two…
2
votes
3 answers

Disambiguate record update with DuplicateRecordFields

I'm using the DuplicateRecordFields (+OverloadedLabels) extension, and I've run into a situation where I can't figure out how to disambiguate in a record update. Here is a simplified example: data A = A { name :: String } data B = B { name :: String…
theduke
  • 3,027
  • 4
  • 29
  • 28
2
votes
1 answer

Default overload for ambiguous calls

Say I have the following two functions: void Foo(IEnumerable bar) { if(bar == null) return; foreach(var b in bar) { Console.Write(b); } } and void Foo(string bar) { Foo(new string[] { bar }); } Those two are…
Jcl
  • 27,696
  • 5
  • 61
  • 92
2
votes
1 answer

Android Studio ambiguous method call for Object.toString

Others have seen the "Ambiguous Method Call" error in Android Studio for getClass() But I'm seeing it for Object.toString() Has anyone else seen that? The version of Android Studio I have is 0.8.6.
Coder Roadie
  • 838
  • 1
  • 8
  • 11
2
votes
1 answer

Marking one method as preferred to automatically resolve ambiguous calls?

Let's say I define myself a new type of byte stream (similar to OutputStream): public interface MyByteStream { public void write(byte[] data) throws IOException; } Also, I have a helper class that can write Strings to a byte stream, and for…
Markus A.
  • 12,349
  • 8
  • 52
  • 116
2
votes
4 answers

Ambiguity issue when deducing function call

I have the following bit of code which has two versions of the function foo. I'd like if a variable is passed for the foo that takes an AVar type to be called otherwise if a const is passed for the AConst version to be called. #include…
user2338542
2
votes
3 answers

Why there's no ambiguity in the expression `d.f(1);` below in main()?

Why there's no ambiguity in the expression d.f(1); below in main() between Base::f(int) and Derived::f(int) ? class Base { public: void f(int i) {} void f(int i, int j) {} }; class Derived : public Base { public: using Base::f; …
Belloc
  • 6,318
  • 3
  • 22
  • 52
2
votes
1 answer

Why do I get an ambiguous call in vb but not in c#?

I had a class with the following methods in c#: public MyRetType MyMethod(String p1 = null) { MyMethod(); } public MyRetType MyMethod(String p1, String p2, MyClass1 p3, String p4 = null, MyClass2 p5 = null) { ... } I…
raven
  • 2,574
  • 2
  • 27
  • 49