user695652
user695652

Reputation: 4275

Why is pass by value and pass by rvalue overload c++ function call ambiguous?

If I have,

void foo(Bar c);
void foo(Bar&& c);

foo(Bar()); 

why is the call to 'foo' is ambiguous? Isn't Bar() in the foo argument clearly an rValue?

Upvotes: 5

Views: 410

Answers (1)

Kerrek SB
Kerrek SB

Reputation: 477408

Binding to a reference is an "exact match", as is binding to a non-reference, so both overloads are equally good.

In Standardese, this is 13.3.3.1.4 ("Reference binding", [over.ics.ref]):

When a parameter of reference type binds directly (8.5.3) to an argument expression, the implicit conversion sequence is the identity conversion [...]

Upvotes: 4

Related Questions