Namespaces
Variants
Views
Actions

Talk:cpp/language/overload resolution

From cppreference.com

[edit] wrong code snippet in 'Ranking of implicit conversion sequences' section

struct Base {};
struct Derived : Base {} b;
int f(A&); // overload #1
int f(B&); // overload #2
int i = f(b); // b -> B& has rank Exact Match
              // b -> A& has rank Conversion
              // calls f(B&)

What are A and B types used in function arguments ??? --92.255.187.52 06:32, 18 October 2013 (PDT)

Good catch, fixed. --Cubbi (talk) 07:02, 18 October 2013 (PDT)

[edit] Wrong example with list initialization vs non-list initialization

The example for "A list-initialization sequence L1 is better than list-initialization sequence L2 if L1 initializes an std::initializer_list parameter, while L2 does not" is wrong. A right example would be

  void f(int);
  void f(std::initializer_list<int>);
  // call
  f({42});

The example with vector uses two-phase overload resolution on constructors, and in the first phase only initializer list constructors are considered. This is the mechanism by which the vector example is "disambiguated".

litb 91.2.84.210 16:05, 6 November 2014 (PST)

you're right, litb, I made the change. --Cubbi (talk) 16:51, 6 November 2014 (PST)