Re: On deletion of exception objects in C++

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux