purepureluck purepureluck - 1 month ago 6
C++ Question

What happens in a double delete?

Obj *op = new Obj;
Obj *op2 = op;
delete op;
delete op2; // What happens here?

What's the worst that can happen when you accidentally double delete? Does it matter? Is the compiler going to throw an error?

Answer Source

It causes undefined behaviour. Anything can happen. In practice, a runtime crash is probably what I'd expect.