string foo() { return "hello"; }
int main()
{
//below should be illegal for binding a non-const (lvalue) reference to a rvalue
string& tem = foo();
//below should be the correct one as only const reference can be bind to rvalue(most important const)
const string& constTem = foo();
}
类型的临时对象对 std::string&
类型的非常量引用无效初始化std::string
std::string
到 std::string &
的转换 非常量引用只能绑定到左值&&
,而是在演示代码中,我只是使用非常量左值引用!std::string&
from a temporary of type std::string
std::string
to std::string &
A non-const
reference may only be bound to an lvalue&&
, instead in the demo code, I was just using non-const lvalue reference !这里有人能帮我解释一下VS2010的行为吗?是bug吗!?谢谢
Can somone help me explain the behavior of VS2010 here? Is it a bug !? Thanks
这是 VS 编译器的已知问题/功能.他们一直允许这样做,并且似乎没有任何推动删除该扩展.
That is a known issue/feature of the VS compilers. They have always allowed that and there does not seem to be any push into removing that extension.
这篇关于一个 VS2010 错误?允许在没有警告的情况下绑定非常量引用到右值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!