C++ 是否需要重载运算符new和delete?

C++ 是否需要重载运算符new和delete?,c++,gcc,memory-management,operator-overloading,libstdc++,C++,Gcc,Memory Management,Operator Overloading,Libstdc++,在中,我阅读了以下评论: /* Any code using libstdc++ must have externally resolvable overloads * for void * operator new - which means in the .o for the binary, * or in a shared library. static libs don't propogate the symbol * so, look in the translation uni

在中,我阅读了以下评论:

/* Any code using libstdc++ must have externally resolvable overloads
 * for void * operator new - which means in the .o for the binary,
 * or in a shared library. static libs don't propogate the symbol
 * so, look in the translation unit containing main() in squid
 * for the extern version in squid
 */
我想知道这是从哪里来的,这样的要求是在哪里提出的,gcc的哪个版本是对应的。它适用于libstdc++。在我看来,这句话在我的系统中似乎并不正确:如果squid不提供这些符号,事情就会很好地运行,事实上,提供这些符号似乎是正确的。另一方面,我认为开发人员并不是为了好玩才添加注释和重载操作符的。我想在当时的一些配置中需要它们


您能告诉我哪些配置(版本、体系结构、设置等)需要添加这样的运算符定义吗?为什么?

可能重复@AlokSave:也许我遗漏了什么,但从我的阅读方式来看,这个问题讨论了为什么我可能想重载它们,而我问的是什么时候我会让他们超负荷工作。评论中并没有说“必须拥有……如果它想获得一些特别的东西”,而是说“必须拥有”这些重载在任何情况下都是毫无根据的。这对我来说似乎是可疑的。全局新/删除操作符必须是可替换的,这通常是通过在C++运行库中实现默认值来实现的;或者在遇到用户定义的(外部)时通过直接编译器干预来实现。符号。快速检查
lib/util.c
可以发现
xmalloc
xfree
不遵守first
操作符new
的抛出语义。这些重写会带来麻烦。通常,如果要重写一个,应该重写8个可替换的new/delete操作符。抛出变量n-throwing变量和throwing/non-throwing数组变量。请查看LLVMs libc++以获得替换new/delete运算符的正确语义指南。如果不使用C++11,可以省略
noexcept
规范。