为什么按值传递和右值传递c ++函数调用不明确? [英] Why is pass by value and pass by rvalue overload c++ function call ambiguous?

查看:66
本文介绍了为什么按值传递和右值传递c ++函数调用不明确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有,

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

foo(Bar()); 

为什么对 foo的调用不明确?
foo参数中的Bar()显然不是rValue吗?

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

推荐答案

绑定到引用是完全匹配,因为绑定到非引用,所以两个重载都同样好。

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

在Standardese中,这是13.3.3.1.4(参考绑定 ,[over.ics.ref]):

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


当引用类型的参数直接绑定(8.5.3)到参数表达式时,隐式转换序列是身份转换[...]

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

这篇关于为什么按值传递和右值传递c ++函数调用不明确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆