Why the below piece of code is not crashing , though i have deleted the object?

后端 未结 10 1216
北海茫月
北海茫月 2021-01-18 02:29
class object
{
  public:
    void check()
    {
      std::cout<<\"I am doing ok...\"<

        
10条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-18 02:48

    Even if the method call was using the this pointer it would not be guaranteed to crash. The pointer p when deleted is not being zeroed so is still pointing to the same address in memory. Depending on the implementation of new/delete and the heap manager this memory might not even be resused so the use of p may still continue to work even though the memory has been released.

提交回复
热议问题