c++ - C++14 是否要求删除表达式必须调用 `void operator::delete(void*, std::size_t)` 而不是 `void::operator delete(void*)` ?

标签 c++ memory-management new-operator c++14

根据 this

void operator delete  (void*);                                    (1)   
void operator delete[](void*);                                    (2)   
void operator delete  (void*, const std::nothrow_t&);             (3)   
void operator delete[](void*, const std::nothrow_t&);             (4)   
void operator delete(void*, std::size_t)                          (5)
void operator delete[](void*, std::size_t)                        (6)
void operator delete(void*, std::size_t, const std::nothrow_t&)   (7)
void operator delete[](void*, std::size_t, const std::nothrow_t&) (8)

(5-8) Called instead of (1-4) if a user-defined replacement is provided. The standard library implementations are identical to (1-4).

我相信引用的陈述是正确的;但是,我无法根据 C++14 标准草案 n3797 确认它。

我检查了 3.7.4 和 18.6,没有发现任何明确要求删除表达式必须调用 void::operator delete(void*, std::size_t) 而不是 void : :operator delete(void*) 如果前者存在。

你能给我指一下标准草案的右页吗?

最佳答案

释放函数的选择解释如下:

5.3.5 删除[expr.delete]

10 If the type is complete and if deallocation function lookup finds both a usual deallocation function with only a pointer parameter and a usual deallocation function with both a pointer parameter and a size parameter, then the selected deallocation function shall be the one with two parameters. Otherwise, the selected deallocation function shall be the function with one parameter.

关于c++ - C++14 是否要求删除表达式必须调用 `void operator::delete(void*, std::size_t)` 而不是 `void::operator delete(void*)` ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24603894/

相关文章:

c++ - 跨 DLL 的内存/堆管理

c++ - 如何强制 new 运算符返回的指针为 32 字节对齐

c++ - 使用shared_ptr处理可靠的命令模式

c++ - 函数不断覆盖以前的结构数据

c# - 通过 lambda 使对象保持事件状态

memory-management - 垃圾回收机制是如何工作的?

c++ - 在对象评估时调用哪个运算符?

c++ - Cython 调用 MKL 通过 vdMul 在元素乘法上崩溃

c++ - 我真的可以用圆括号初始化数组吗?

c++ - 使用 C++ 动态分配结构数组