Contents Up << >>

What's the deal with destructors?

A destructor gives an object its last rites.

Destructors are used to release any resources allocated by the object. E.g., a Lock class might lock a semaphore, and the destructor will release that semaphore. The most common example is when the constructor uses " new", and the destructor uses "delete".

Destructors are a "prepare to die" method. They are often abbreviated "dtor".

  • Operator overloading