On deletion of exception objects in C++
John (Eljay) Love-Jensen
eljay@adobe.com
Tue Feb 23 17:05:00 GMT 2010
Hi Debarshi,
You may find this helpful to understand what is happening:
struct E
{
E() { std::cerr << "E ctor " << (void*)this << "\n"; }
~E() { std::cerr << "E dtor " << (void*)this << "\n"; }
E(E const&) { std::cerr << "E copy ctor " << (void*)this << "\n"; }
E& operator = (E const& rhs) { std::cerr << "E assignment "
<< (void*)this << " <--" << (void*)&rhs << "\n"; }
};
My output has:
E ctor 0x100150
E copy ctor 0x100200
E copy ctor 0x1003f0
E dtor 0x100200
E dtor 0x1003f0
E dtor 0x1003f0
Your delete (&e); is not deleting the one on the heap.
You are lucky you got a crash.
I did not get a crash, which is far worse -- silent but deadly.
HTH,
--Eljay
More information about the Gcc-help
mailing list