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

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

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

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

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

      放置新建和删除

      时间:2023-10-06

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

      <tfoot id='iwdjl'></tfoot>

    2. <legend id='iwdjl'><style id='iwdjl'><dir id='iwdjl'><q id='iwdjl'></q></dir></style></legend>
          <bdo id='iwdjl'></bdo><ul id='iwdjl'></ul>

              <tbody id='iwdjl'></tbody>

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

              1. 本文介绍了放置新建和删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                删除这里分配的所有内存的正确方法是什么?

                What is the right method to delete all the memory allocated here?

                  const char* charString = "Hello, World";
                  void *mem = ::operator new(sizeof(Buffer) + strlen(charString) + 1);
                  Buffer* buf = new(mem) Buffer(strlen(charString));
                
                  delete (char*)buf;
                

                  const char* charString = "Hello, World";
                  void *mem = ::operator new(sizeof(Buffer) + strlen(charString) + 1);
                  Buffer* buf = new(mem) Buffer(strlen(charString));
                
                  delete buf;
                

                还是两者都一样?

                推荐答案

                正确的方法是:

                buf->~Buffer();
                ::operator delete(mem);
                

                您只能使用 delete operator 删除您从 new operator 收到的内容.如果直接调用operator new函数,也必须直接调用operator delete函数,并且必须手动调用析构函数.

                You can only delete with the delete operator what you received from the new operator. If you directly call the operator new function, you must also directly call the operator delete function, and must manually call the destructor as well.

                这篇关于放置新建和删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:使 LibCurl 与 Visual Studio 2013 一起使用 下一篇:c=a+++b 运算是什么意思?

                相关文章

                最新文章

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

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

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