How can I determine if a C++ object has been deallocated?

前端 未结 6 1792
情话喂你
情话喂你 2020-11-29 13:38

I have a previous question that was answered in which I describe difficulties catching an exception when I try to access an object that has been deallocated by a third-party

6条回答
  •  萌比男神i
    2020-11-29 13:57

    I think you're asking the wrong question. The question really ought to be:

    Why do I feel like I need to look at some address in order to find out whether the pointer pointing there refers to an object or to the garbage left after an ex-object was deleted?

    Honestly, you shouldn't be in that situation. If an object is deleted, why are you left with a pointer to its ex-address? Ideally, the pointer should be out of scope. If that isn't possible in your code, it should have been set to NULL.

提交回复
热议问题