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

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

      2. <small id='Ij6ki'></small><noframes id='Ij6ki'>

        为什么不在 C++11 中删除具有副作用未定义行为的析构函数的对象?

        时间:2023-09-26

        1. <tfoot id='mHVbF'></tfoot>

              <bdo id='mHVbF'></bdo><ul id='mHVbF'></ul>
              <legend id='mHVbF'><style id='mHVbF'><dir id='mHVbF'><q id='mHVbF'></q></dir></style></legend>

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

                  <i id='mHVbF'><tr id='mHVbF'><dt id='mHVbF'><q id='mHVbF'><span id='mHVbF'><b id='mHVbF'><form id='mHVbF'><ins id='mHVbF'></ins><ul id='mHVbF'></ul><sub id='mHVbF'></sub></form><legend id='mHVbF'></legend><bdo id='mHVbF'><pre id='mHVbF'><center id='mHVbF'></center></pre></bdo></b><th id='mHVbF'></th></span></q></dt></tr></i><div id='mHVbF'><tfoot id='mHVbF'></tfoot><dl id='mHVbF'><fieldset id='mHVbF'></fieldset></dl></div>
                    <tbody id='mHVbF'></tbody>
                  本文介绍了为什么不在 C++11 中删除具有副作用未定义行为的析构函数的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这个答案引用了 C++11 Standard 3.8:

                  This answer quotes C++11 Standard 3.8:

                  如果没有显式调用析构函数或者如果没有使用删除表达式(5.3.5)来释放存储,则不应隐式调用析构函数,任何依赖于由析构函数产生的副作用的程序析构函数有未定义的行为.

                  if there is no explicit call to the destructor or if a delete-expression (5.3.5) is not used to release the storage, the destructor shall not be implicitly called and any program that depends on the side eects produced by the destructor has undened behavior.

                  关于未调用析构函数的部分很清楚.现在假设跳过的析构函数有一个应该影响程序行为的副作用.

                  The part about the destructor not being called is clear. Now suppose the skipped destructor had a side effect that should have affected the program behavior.

                  为什么现在程序行为未定义?为什么不跳过副作用(因为没有调用析构函数)并且程序正常运行而没有应用副作用?

                  Why is the program behavior undefined now? Why wouldn't the side effects be skipped (since the destructor is not called) and the program run normally just without side effects applied?

                  推荐答案

                  重要的部分是那一段的第一部分(重点是我的):

                  The important part is the first part of that paragraph (emphasis mine):

                  程序可以通过重用对象占用的存储空间来结束任何对象的生命周期 ...

                  如果您只是将存储重用于其析构函数被调用的对象,那么您会得到未定义的行为.例如,对象可能已经启动了一个线程,或者注册了一个回调,或者外部组件可能期望对象仍然存在的一些其他操作.

                  If you simply reuse the storage for an object whose destructor has not been called, then you get undefined behaviour. For example, the object could have started a thread, or registered a callback, or some other action where an external component might expect the object to still exist.

                  这篇关于为什么不在 C++11 中删除具有副作用未定义行为的析构函数的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 C++ 中检查内存泄漏的最佳方法是什么? 下一篇:VS2010 报告 DLL 中静态类的错误内存泄漏

                  相关文章

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

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

                      <tfoot id='bhSWk'></tfoot>

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

                      <legend id='bhSWk'><style id='bhSWk'><dir id='bhSWk'><q id='bhSWk'></q></dir></style></legend>