Test, if object was deleted

Posted by justik on Stack Overflow See other posts from Stack Overflow or by justik
Published on 2010-05-03T12:37:30Z Indexed on 2010/05/03 12:48 UTC
Read the original article Hit count: 275

Filed under:
|
|
|

Look to the following code, please:

class Node
{
private:
    double x, y;
public:
    Node (double xx, double yy): x(xx), y(yy){}
};

int main()
{
  Node *n1 = new Node(1,1);
  Node *n2 = n1;

  delete n2; 
  n2 = NULL;

  if (n1 != NULL) //Bad test
  {
     delete n1;   //throw an exception
  }
}

There are two pointers n1, n2 pointed to the same object. I would like to detect whether n2 was deleted using n1 pointer test. But this test results in exception.

Is there any way how to determine whether the object was deleted (or was not deleted) using n1 pointer ? Thanks for your help.

© Stack Overflow or respective owner

Related posts about c++

Related posts about object