【发布时间】:2020-01-15 11:58:03
【问题描述】:
在有效的现代 C++ 中
class Widget {
public:
Widget(Widget&& rhs); // rhs is an lvalue, though it has
… // an rvalue reference type
};
rhs 是一个左值
void f(Widget&& param); // rvalue reference
param 是一个右值引用
rhs 和 param 有什么区别?
【问题讨论】:
-
rhs 是构造函数内部的右值。这意味着如果要将rhs用作右值引用,则应在函数内部使用
std::move(),否则将被解释为左值引用。 -
@Ladence 这不准确,尽管结果是正确的
-
关于 dup:问题不一样但接受的答案提供了这个问题的答案:没有区别。
标签: c++ c++11 reference rvalue lvalue