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

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

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

    3. 删除与删除[]

      时间:2023-07-18
    4. <tfoot id='jMId0'></tfoot>
        <tbody id='jMId0'></tbody>

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

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

                <bdo id='jMId0'></bdo><ul id='jMId0'></ul>
                本文介绍了删除与删除[]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                <块引用>

                可能的重复:
                (POD)释放内存:delete[]等于delete吗?

                当我学习 C++ 时,那是很久以前的事了.我被告知永远不要使用 deletedelete[] 因为在单个对象上执行 delete[] 将等同于 delete.知道不要太相信老师,我想知道这是真的吗?

                是否有理由调用 delete 而不是 delete[]?

                我已经扫描了 SO 中可能相关的问题,但没有找到任何明确的答案.

                解决方案

                来自标准 (5.3.5/2) :

                <块引用>

                在第一个选项中(删除对象),操作数的值delete 应该是一个指向 a 的指针非数组对象或指向 a 的指针代表基础的子对象 (1.8)此类对象的类(第 10 条).如果不是,则行为未定义.

                在第二种选择中(删除数组),操作数的值delete 应该是指针值这是由先前的数组产生的新表达.如果没有,则行为未定义.

                所以不:它们绝不是等价的!

                Possible Duplicate:
                ( POD )freeing memory : is delete[] equal to delete ?

                When I was taught C++, this was a long time ago. I was told to never use delete but delete[] as performing delete[] on a single object will be equivalent to delete. Knowing not to trust teachers too much I wonder, Is this true?

                Is there ever a reason to call delete instead of delete[]?

                I've scanned the possibly related questions in SO, but haven't found any clear answer.

                解决方案

                From the standard (5.3.5/2) :

                In the first alternative (delete object), the value of the operand of delete shall be a pointer to a non-array object or a pointer to a sub-object (1.8) representing a base class of such an object (clause 10). If not, the behavior is undefined.

                In the second alternative (delete array), the value of the operand of delete shall be the pointer value which resulted from a previous array new-expression. If not, the behavior is undefined.

                So no : they are in no way equivalent !

                这篇关于删除与删除[]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

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

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

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