【发布时间】:2017-08-24 05:07:09
【问题描述】:
我有代码
void print(string &&str) {
cout << str << endl;
}
int main() {
string tmp("Hello");
string&& str = move(tmp);
//print(move(str));
print(str);
return 0;
}
编译后我得到error: cannot bind rvalue reference of type 'std::__cxx11::string&&' to lvalue of type 'std::__cxx11::string'。
但是str 是对 r-value 的 r-value 引用(不是吗?),所以我相信将它传递给 print 是有道理的。为什么会出现这个错误?
【问题讨论】:
-
当右值引用获得一个名称时,它会失去它的右值引用属性...
标签: c++ c++11 pass-by-reference rvalue-reference rvalue