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

      <legend id='ubljS'><style id='ubljS'><dir id='ubljS'><q id='ubljS'></q></dir></style></legend>
      1. <tfoot id='ubljS'></tfoot>

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

      2. <i id='ubljS'><tr id='ubljS'><dt id='ubljS'><q id='ubljS'><span id='ubljS'><b id='ubljS'><form id='ubljS'><ins id='ubljS'></ins><ul id='ubljS'></ul><sub id='ubljS'></sub></form><legend id='ubljS'></legend><bdo id='ubljS'><pre id='ubljS'><center id='ubljS'></center></pre></bdo></b><th id='ubljS'></th></span></q></dt></tr></i><div id='ubljS'><tfoot id='ubljS'></tfoot><dl id='ubljS'><fieldset id='ubljS'></fieldset></dl></div>
      3. 我怎么能合理地重载放置运算符 new?

        时间:2023-07-02

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

              <tbody id='v1VJi'></tbody>

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

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

                  本文介绍了我怎么能合理地重载放置运算符 new?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  C++ 允许重载 operator new - 全局和每个类 - 通常 operator newoperator new[] 一起使用new[] 语句和放置 operator new 分开.

                  C++ allows overloading operator new - both global and per-class - usual operator new, operator new[] used with new[] statement and placement operator new separately.

                  这三个中的前两个通常会因使用自定义分配器和添加跟踪而过载.但是放置 operator new 看起来很简单——它实际上什么都不做.例如,在 Visual C++ 中,默认实现只返回传递给调用的地址:

                  The former two of those three are usually overloaded for using customized allocators and adding tracing. But placement operator new seems pretty straightforward - it actually does nothing inside. For example, in Visual C++ the default implementation just returns the address passed into the call:

                  //from new.h
                  inline void* operator new( size_t, void* where )
                  {
                     return where;
                  }
                  

                  它还能做什么?为什么以及如何合理地重载放置 operator new?

                  What else could it do? Why and how could I sensibly overload placement operator new?

                  推荐答案

                  正确答案是你不能替换新的运算符位置.

                  §18.4. 1.3 安置表格
                  这些函数是保留的,C++ 程序不能定义替换标准 C++ 库中版本的函数.

                  §18.4.1.3 Placement forms
                  These functions are reserved, a C++ program may not define functions that displace the versions in the Standard C++ library.

                  基本原理:分配和释放操作符的唯一目的是分配和释放内存,所以当给定内存时,什么都不用做.(标准特别指出这些功能故意不执行其他操作.")

                  The rationale: The only purpose of the allocation and deallocation operators is to allocate and deallocate memory, so when given memory nothing more should be done. (The standard specifically notes that these functions "Intentionally perform no other action.")

                  这篇关于我怎么能合理地重载放置运算符 new?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在代码优化期间,C++11 编译器是否会将局部变量转换为右值? 下一篇:关于 C 中除以零的一些事情

                  相关文章

                  <small id='7Sq5T'></small><noframes id='7Sq5T'>

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

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