Is “delete p; p = NULL(nullptr);” an antipattern?

前端 未结 7 1424
长发绾君心
长发绾君心 2021-02-05 13:35

Searching something on SO, I stumbled across this question and one of the comments to the most voted answer (the fifth comment to that most voted answer) suggests that del

相关标签:
7条回答
  • 2021-02-05 14:10

    In my opinion the anti-pattern is not delete p; p = NULL;, it's assert(this != NULL).

    I use the anti-pattern as you call it for two reasons - first to enhance the likelyhood that bad code will crash spectacularly without hiding, and second to make the core problem more obvious in debugging. I wouldn't litter my code with asserts just on the off chance that it might catch something.

    0 讨论(0)
提交回复
热议问题