What happens to an address after delete operator has been applied to it in C++?

前端 未结 5 609
春和景丽
春和景丽 2020-12-19 09:51

If I delete a pointer as follows for example:

delete myPointer;

And, after that did not assign 0

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-19 10:19

    Not always but it can change. In designing a hash table , I found the address to have changed after around 30 error-free tests on 1000 objects. It changed exactly after a delete operation. Solution: use T_ *const to store a side address to the object that will be deleted where T_ is pointer type and the const qualifier to ensure the address doesn't change.

提交回复
热议问题