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

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 02:25:52

问题


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?


回答1:


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 [...]



来源:https://stackoverflow.com/questions/38847321/method-overloading-with-move-semantic

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!