在C ++ 03中,您可以使用const&
技巧(或“最重要的const”)将临时的生命周期延长到引用的生命周期。我的问题是,在C ++ 0x中,这种行为是否扩展到rvalue引用? I.e auto&& x = someFunction();
答案 0 :(得分:4)
根据[class.temporary]
,如果编译然后是,则临时的生命周期延长。
答案 1 :(得分:0)
它在VC10 SP1上完美编译:
int && Get()
{
return 10;
}
const auto&& y=Get();