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

  • <tfoot id='F2CXW'></tfoot>
  • <small id='F2CXW'></small><noframes id='F2CXW'>

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

        std::vector 元素的销毁顺序

        时间:2023-10-07
        <i id='K8kJ5'><tr id='K8kJ5'><dt id='K8kJ5'><q id='K8kJ5'><span id='K8kJ5'><b id='K8kJ5'><form id='K8kJ5'><ins id='K8kJ5'></ins><ul id='K8kJ5'></ul><sub id='K8kJ5'></sub></form><legend id='K8kJ5'></legend><bdo id='K8kJ5'><pre id='K8kJ5'><center id='K8kJ5'></center></pre></bdo></b><th id='K8kJ5'></th></span></q></dt></tr></i><div id='K8kJ5'><tfoot id='K8kJ5'></tfoot><dl id='K8kJ5'><fieldset id='K8kJ5'></fieldset></dl></div>
          <tbody id='K8kJ5'></tbody>

        1. <legend id='K8kJ5'><style id='K8kJ5'><dir id='K8kJ5'><q id='K8kJ5'></q></dir></style></legend>
              <bdo id='K8kJ5'></bdo><ul id='K8kJ5'></ul>

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

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

                  本文介绍了std::vector 元素的销毁顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  可能的重复:
                  STL容器元素销毁顺序

                  有没有保证 std::vector 的元素会从最后到第一个销毁?

                  Is there a guarantee the the elements of an std::vector would be destroyed from last to first?

                  推荐答案

                  2003:5.3.5/6 关于 delete[] 的说明:

                  2003:5.3.5/6 says about delete[]:

                  delete 表达式将调用要删除的对象或数组元素的析构函数(如果有).在数组的情况下,元素将按照地址递减的顺序销毁(即,按照其构造函数完成的相反顺序;参见 12.6.2).

                  The delete-expression will invoke the destructor (if any) for the object or the elements of the array being deleted. In the case of an array, the elements will be destroyed in order of decreasing address (that is, in reverse order of the completion of their constructor; see 12.6.2).

                  因此,如果您的 std::vector 对象的分配器使用 delete[] 那么,是的,它必然会以相反的顺序销毁元素.

                  So if your std::vector object's allocator uses delete[] then, yes, it is bound to destroy elements in reverse order.

                  但是,不能保证您的 std::vector 会以这种方式工作(事实上,它很可能不会),而且我找不到任何特定于容器.

                  However, there is no guarantee that your std::vector will work this way (and, in fact, it most likely does not), and I can't find any citations specific to the container.

                  真的,我认为这完全取决于您的分配器,而 2003:20.1.5(列出了对分配器的要求)似乎对此没有任何说明.

                  Really, I think it's all down to your allocator and 2003:20.1.5 (which lists the requirements placed upon allocators) doesn't appear to say anything about it.

                  这篇关于std::vector 元素的销毁顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:std::vector 在 push_back 期间多次调用析构函数? 下一篇:C++ std::vector 的独立 std::threads

                  相关文章

                  最新文章

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

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

                  1. <tfoot id='m0KAg'></tfoot>
                    1. <small id='m0KAg'></small><noframes id='m0KAg'>