我正在观看 herb sutter cpp2 的视频,其中说移动局部变量的地址是 C++ 中的编译时错误,但是当我尝试移动局部变量的地址时,我没有收到错误,请解释我他想说什么。
#include <iostream>
void f(std::string* s)
{
*s = "jit";
}
void fun(std::string s)
{
if (0) {
f(std::move(&s));
}
else
f(std::move(&s));
}
int main()
{
std::string s = "hi";
fun(s);
}