NULL check before deleting an object with an overloaded delete

前端 未结 11 1794
野性不改
野性不改 2020-12-18 18:24

This came up as one of the code review comments.

Is it a good idea to check for NULL before calling delete for any object?

I do understand delete operator c

11条回答
  •  天涯浪人
    2020-12-18 18:36

    From Standard docs, 18.5.1.1.13 under delete,

    Default behavior: If ptr is null, does nothing. Otherwise, reclaims the storage allocated by the earlier call to operator new.

    So, you don't have to check by default..

提交回复
热议问题