This question already has an answer here:
- Passing int&& to f(int&&) 3 answers
I have code
void print(string &&str) {
cout << str << endl;
}
int main() {
string tmp("Hello");
string&& str = move(tmp);
//print(move(str));
print(str);
return 0;
}
After compiling I get error: cannot bind rvalue reference of type 'std::__cxx11::string&&' to lvalue of type 'std::__cxx11::string'
.
But str
is r-value reference to r-value(isn't it?), so passing it into print
makes sense I believe. Why this error occurred?
Aucun commentaire:
Enregistrer un commentaire