Is it safe to delete a NULL pointer?

前端 未结 7 1430
忘掉有多难
忘掉有多难 2020-11-22 06:51

Is it safe to delete a NULL pointer?

And is it a good coding style?

7条回答
  •  鱼传尺愫
    2020-11-22 07:01

    To complement ruslik's answer, in C++14 you can use this construction:

    delete std::exchange(heapObject, nullptr);
    

提交回复
热议问题