gpt4 book ai didi

c++ - C++17 标准对 nullptr 调用 delete 有何规定?

转载 作者:行者123 更新时间:2023-12-02 03:28:45 25 4
gpt4 key购买 nike

C++03 标准说的是:

5.3.5 Delete

[...] In either alternative, if the value of the operand of delete is the null pointer the operation has no effect.[...]

char *p = nullptr;
delete p; //no effect

这意味着,在c++中删除空指针是有效的。

C++17 标准对 nullptr 指针调用 delete 有何规定?

最佳答案

是的,它是有效的,并且会导致空操作。 reference

If expression evaluates to a null pointer value, no destructors are called, and the deallocation function is not called.

关于c++ - C++17 标准对 nullptr 调用 delete 有何规定?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47354881/

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