本文介绍了一个VS2010错误?允许绑定非const引用到右值WITHOUT EVEN警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
的非临时引用无效初始化 std :: string& 字符串
警告C4239: :'initializing':
从 std :: string 转换为 std :: string& -const
引用只能绑定到一个左值
错误或警告,WHY? !
我知道VS2010中的右值引用可以用于与右值绑定,但我不使用&& 示例代码,我只是使用非常见的值引用!
- GCC is the good one to give a compile error: invalid initialization of non-const reference of type std::string& from a temporary of type std::string
- VS2008 is not too bad as at least it gives a compile warning:warning C4239: nonstandard extension used : 'initializing' :conversion from std::string to std::string & A non-constreference may only be bound to an lvalue
- Here comes the problematic one - VS2010(SP1) comples fine WITHOUT anyerror or warning, WHY ??!!I know rvalue reference in VS2010 can be used to bind with rvalue but I am NOT using &&, instead in the demo code, I was just using non-const lvalue reference !
可以somone帮我解释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错误?允许绑定非const引用到右值WITHOUT EVEN警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!