1

Possible Duplicate:
Undefined, unspecified and implementation-defined behavior

I know calling delete on same object is disastrous. But that is true as long as the memory is not reallocated for some other object before the second call to delete. But, even doing the below is wrong? If I remove the cout, the code is not dumping core.

int main()
{
    A *a1 = new A();
    delete a1;
    cout<<a1<<endl;
    delete a1;
}
Community
  • 1
  • 1
rahul
  • 5,837
  • 3
  • 25
  • 39

1 Answers1

7

See What happens in a double delete?:

Yes, it is very wrong.

The big problem is that the behavior is undefined. So it you might get away with it in one situation on one compiler, but in general it tends to cause a crash.

Community
  • 1
  • 1
Nathan Monteleone
  • 5,110
  • 26
  • 42