• <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 中删除具有副作用未定义行为的析构函数的对象?

        Why is not deleting an object that has a destructor with a side effect undefined behavior in C++11?(为什么不在 C++11 中删除具有副作用未定义行为的析构函数的对象?)

        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 中删除具有副作用未定义行为的析构函数的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Constructor initialization Vs assignment(构造函数初始化 Vs 赋值)
                  Is a `=default` move constructor equivalent to a member-wise move constructor?(`=default` 移动构造函数是否等同于成员移动构造函数?)
                  Has the new C++11 member initialization feature at declaration made initialization lists obsolete?(声明时新的 C++11 成员初始化功能是否使初始化列表过时了?)
                  Order of constructor call in virtual inheritance(虚继承中构造函数调用的顺序)
                  How to use sfinae for selecting constructors?(如何使用 sfinae 选择构造函数?)
                  Initializing a union with a non-trivial constructor(使用非平凡的构造函数初始化联合)

                    <tbody id='bhSWk'></tbody>
                    <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>