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

  • <legend id='qIwTX'><style id='qIwTX'><dir id='qIwTX'><q id='qIwTX'></q></dir></style></legend>
      <bdo id='qIwTX'></bdo><ul id='qIwTX'></ul>
    1. <tfoot id='qIwTX'></tfoot>

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

        为什么不删除将指针设置为 NULL?

        Why doesn#39;t delete set the pointer to NULL?(为什么不删除将指针设置为 NULL?)

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

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

          <tfoot id='ry4aP'></tfoot>
              <tbody id='ry4aP'></tbody>

                  <i id='ry4aP'><tr id='ry4aP'><dt id='ry4aP'><q id='ry4aP'><span id='ry4aP'><b id='ry4aP'><form id='ry4aP'><ins id='ry4aP'></ins><ul id='ry4aP'></ul><sub id='ry4aP'></sub></form><legend id='ry4aP'></legend><bdo id='ry4aP'><pre id='ry4aP'><center id='ry4aP'></center></pre></bdo></b><th id='ry4aP'></th></span></q></dt></tr></i><div id='ry4aP'><tfoot id='ry4aP'></tfoot><dl id='ry4aP'><fieldset id='ry4aP'></fieldset></dl></div>
                1. <legend id='ry4aP'><style id='ry4aP'><dir id='ry4aP'><q id='ry4aP'></q></dir></style></legend>
                  本文介绍了为什么不删除将指针设置为 NULL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我一直想知道为什么在 delete 之后将指针自动设置为 NULL 不是标准的一部分.如果这一点得到处理,那么许多由于无效指针导致的崩溃就不会发生.但话虽如此,我可以想到标准会限制这一点的几个原因:

                  <块引用>

                  1. 性能:

                    附加指令可能会降低 delete 的性能.

                  2. 可能是因为 const 指针.

                    然后,我猜标准本可以为这种特殊情况做一些事情.

                  有人知道不允许这样做的确切原因吗?

                  解决方案

                  Stroustrup 本人 答案.摘录:

                  <块引用>

                  C++ 明确允许执行删除归零一个左值操作数,我曾希望实现会做到这一点,但这个想法似乎没有受到实施者的欢迎.

                  但他提出的主要问题是,delete 的参数不必是左值.

                  I always wondered why automatic setting of the pointer to NULL after delete is not part of the standard. If this gets taken care of then many of the crashes due to an invalid pointer would not occur. But having said that I can think of couple of reasons why the standard would have restricted this:

                  1. Performance:

                    An additional instruction could slow down the delete performance.

                  2. Could it be because of const pointers.

                    Then again standard could have done something for this special case I guess.

                  Does anyone know exact reasons for not allowing this?

                  解决方案

                  Stroustrup himself answers. An excerpt:

                  C++ explicitly allows an implementation of delete to zero out an lvalue operand, and I had hoped that implementations would do that, but that idea doesn't seem to have become popular with implementers.

                  But the main issue he raises is that delete's argument need not be an lvalue.

                  这篇关于为什么不删除将指针设置为 NULL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to limit the number of running instances in C++(C++中如何限制运行实例的数量)
                  Using boost::asio::async_read with stdin?(将 boost::asio::async_read 与 stdin 一起使用?)
                  How to find out what dependencies (i.e other Boost libraries) a particular Boost library requires?(如何找出特定 Boost 库需要哪些依赖项(即其他 Boost 库)?)
                  What#39;s the purpose of a leading quot;::quot; in a C++ method call(引导“::的目的是什么?在 C++ 方法调用中)
                  Boost Spirit x3: parse into structs(Boost Spirit x3:解析为结构体)
                  How boost auto-linking makes choice?(boost自动链接如何做出选择?)
                  <i id='KlD2c'><tr id='KlD2c'><dt id='KlD2c'><q id='KlD2c'><span id='KlD2c'><b id='KlD2c'><form id='KlD2c'><ins id='KlD2c'></ins><ul id='KlD2c'></ul><sub id='KlD2c'></sub></form><legend id='KlD2c'></legend><bdo id='KlD2c'><pre id='KlD2c'><center id='KlD2c'></center></pre></bdo></b><th id='KlD2c'></th></span></q></dt></tr></i><div id='KlD2c'><tfoot id='KlD2c'></tfoot><dl id='KlD2c'><fieldset id='KlD2c'></fieldset></dl></div>

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

                      <tfoot id='KlD2c'></tfoot>
                      <legend id='KlD2c'><style id='KlD2c'><dir id='KlD2c'><q id='KlD2c'></q></dir></style></legend>
                      • <bdo id='KlD2c'></bdo><ul id='KlD2c'></ul>

                              <tbody id='KlD2c'></tbody>