purepureluck purepureluck - 7 months ago 44
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download