尝试更多地使用 rightvalues 但我很困惑,我应该如何设计我想要使用正确值的函数:
// Pass by whatever-it's-called
void RockyBalboa::DoSomething(std::string&& str){
m_fighters.push_back(str);
}
// Pass by reference
void RockyBalboa::DoSomething(std::string& str){
m_fighters.push_back(std::move(str));
}
这两个函数调用之间的有效区别是什么?当我用双&符号传递它并使用时会发生什么std::move
?