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/