gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:10:44 26 4
gpt4 key购买 nike

根据 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com