use*_*162 3 c++ rvalue-reference move-semantics c++11
哦,我在rvalue-references理解中发现了一个问题.问题:
int&& foo()
{
int n = 5;
return std::move(n);
}
int bar()
{
int y = 10;
return y;
}
int main()
{
int&& p = foo();
bar();
std::cout << p;
}
Run Code Online (Sandbox Code Playgroud)
编译器不写错误或警告我们从函数foo返回本地地址.我将在功能栏中将值5替换为10.但结果是5.如果我改变std :: move to static_cast编译器给出错误,结果为10.为什么会这样?我使用gcc 4.8.1.