implicit conversion sequence in function overloading


I don't understand how the compiler chooses the best candidates. For example, let's have the following code:

int function(double, int, int){...} int function(int, double, double){...}

If the second function needs to convert two variables and the first one has to only convert one variable, how come the first one isn't chosen? Why is this an ambiguous situation?



Why is this an ambiguous situation?


According to §13.3.3/1,


Given these definitions, a viable function F1 is defined to be a <em>better</em> function than another viable function F2 <strong>if for all arguments <em>i</em>, ICS <em>i</em> (F1) is not a worse conversion sequence than ICS <em>i</em> (F2)</strong>, and then

— for some argument <em>j</em>, ICS <em>j</em> (F1) is a better conversion sequence than ICS <em>j</em> (F2), or, if not that,

— [...]


Therefore a call like function(0., 0., 0.) is ambiguous; Neither of the overloads is a better match than the other.

Consider template argument deduction from a function call - if a template parameter T is used in several function parameters (like T a, T b, T c) and for two of the arguments of the call it is deduced as int, but for the third one as double, should that really result in a successful deduction with T=int?

Overload resolution doesn't count the better matches and calls the winner - that wouldn't be decisive enough.

Imagine a jigsaw puzzle - is a piece really a better match for a gap if it fills in better at two ends but worse on another one?


  • standard conversions: Array-to-pointer conversion (strings)
  • How to get component version from Joomla?
  • Calculating percentage using PIG latin
  • Chaining implicit conversion operators
  • recursive variadic template can't deduce argument
  • Get all root sites listed in share point Admin center using graph api beta
  • StringSplitOptions.RemoveEmptyEntries equivalent for TextFieldParser
  • ANTLR generating empty conditions
  • Excel comparison with multiple IFs
  • Converting Negative Decimal To String Loses the -
  • Why do the numeric format strings in C# round the number when not using decimals (F0)?
  • Getting random data from a MySQL database but not repeating data
  • Python functions: Pass global variables if only accessing them?
  • Sending keystrokes from a C# application to a Java application - strange behaviour?
  • How to get a list of all blobs in a repository in Git
  • How do I write a lambda expression that looks like a method?
  • Use double quote then curly brace in powershell -Command
  • Greek letters in a GUI - PYTHON
  • What's the point of nonfinal singleton objects in scala?
  • Get last insert id of Postgresql
  • Is it possible to generate a unique numeric value for each row in an iSeries table without looping?
  • Override bootstrap style not working
  • C++ - Is destructor called when a vector holds objects?
  • Class implementation in a header file == bad style? [duplicate]
  • 'include' of functions in groovy scripts
  • RavenDB indexing errors
  • Slicing an SPA into several components and use AngularJS
  • how to solve invalid conversion specifier warning in iphone app
  • abstracting over a collection
  • SAXReader not re-ecape characters
  • Create DicomImage from scratch using Dcmtk
  • Why Encoding.ASCII != ASCIIEncoding.Default in C#?
  • one Local Olampyad Questions on Informatic in 2011
  • MVC3 Razor - ListBox pre-select not working
  • JavaScriptCore crash on iOS9
  • SVN: Merging two branches together
  • Transpose CSV data with awk (pivot transformation)
  • KeystoneJS: Relationships in Admin UI not updating
  • Why joiner is not used after Sequence generator or Update statergy
  • Net Present Value in Excel for Grouped Recurring CF