<legend id='gITts'><style id='gITts'><dir id='gITts'><q id='gITts'></q></dir></style></legend>
  • <tfoot id='gITts'></tfoot>
  • <small id='gITts'></small><noframes id='gITts'>

      <i id='gITts'><tr id='gITts'><dt id='gITts'><q id='gITts'><span id='gITts'><b id='gITts'><form id='gITts'><ins id='gITts'></ins><ul id='gITts'></ul><sub id='gITts'></sub></form><legend id='gITts'></legend><bdo id='gITts'><pre id='gITts'><center id='gITts'></center></pre></bdo></b><th id='gITts'></th></span></q></dt></tr></i><div id='gITts'><tfoot id='gITts'></tfoot><dl id='gITts'><fieldset id='gITts'></fieldset></dl></div>

        <bdo id='gITts'></bdo><ul id='gITts'></ul>

        一个 VS2010 错误?允许在没有警告的情况下绑定非

        时间:2023-05-23

        <small id='vvRZ6'></small><noframes id='vvRZ6'>

              <tbody id='vvRZ6'></tbody>
            <i id='vvRZ6'><tr id='vvRZ6'><dt id='vvRZ6'><q id='vvRZ6'><span id='vvRZ6'><b id='vvRZ6'><form id='vvRZ6'><ins id='vvRZ6'></ins><ul id='vvRZ6'></ul><sub id='vvRZ6'></sub></form><legend id='vvRZ6'></legend><bdo id='vvRZ6'><pre id='vvRZ6'><center id='vvRZ6'></center></pre></bdo></b><th id='vvRZ6'></th></span></q></dt></tr></i><div id='vvRZ6'><tfoot id='vvRZ6'></tfoot><dl id='vvRZ6'><fieldset id='vvRZ6'></fieldset></dl></div>
              <tfoot id='vvRZ6'></tfoot>
              • <bdo id='vvRZ6'></bdo><ul id='vvRZ6'></ul>

                1. <legend id='vvRZ6'><style id='vvRZ6'><dir id='vvRZ6'><q id='vvRZ6'></q></dir></style></legend>
                  本文介绍了一个 VS2010 错误?允许在没有警告的情况下绑定非常量引用到右值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..
                  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();   
                  }
                  

                  1. GCC 是给出编译错误的好方法:从 类型的临时对象对 std::string& 类型的非常量引用无效初始化std::string
                  2. VS2008 还不错,至少它给出了一个编译警告:警告 C4239:使用了非标准扩展:正在初始化":从 std::stringstd::string & 的转换 非常量引用只能绑定到左值
                  3. 问题来了 - VS2010(SP1) 没有任何问题错误或警告,为什么??!!我知道 VS2010 中的 rvalue reference 可用于绑定 rvalue 但我没有使用 &&,而是在演示代码中,我只是使用非常量左值引用!
                  1. 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
                  2. 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-const reference may only be bound to an lvalue
                  3. Here comes the problematic one - VS2010(SP1) comples fine WITHOUT any error 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 !

                  这里有人能帮我解释一下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模板网!

                  上一篇:错误 LNK2038:检测到“_MSC_VER"不匹配:值“1600 下一篇:混合调试和发布库/二进制文件 - 不好的做法?

                  相关文章

                  最新文章

                2. <tfoot id='VFXqa'></tfoot>

                    <i id='VFXqa'><tr id='VFXqa'><dt id='VFXqa'><q id='VFXqa'><span id='VFXqa'><b id='VFXqa'><form id='VFXqa'><ins id='VFXqa'></ins><ul id='VFXqa'></ul><sub id='VFXqa'></sub></form><legend id='VFXqa'></legend><bdo id='VFXqa'><pre id='VFXqa'><center id='VFXqa'></center></pre></bdo></b><th id='VFXqa'></th></span></q></dt></tr></i><div id='VFXqa'><tfoot id='VFXqa'></tfoot><dl id='VFXqa'><fieldset id='VFXqa'></fieldset></dl></div>

                  1. <legend id='VFXqa'><style id='VFXqa'><dir id='VFXqa'><q id='VFXqa'></q></dir></style></legend>

                    <small id='VFXqa'></small><noframes id='VFXqa'>

                    • <bdo id='VFXqa'></bdo><ul id='VFXqa'></ul>