Destructor

The primary purpose of the destructor is return an objects dynamic memory so that it can be reused.

Properties of the destructor:

  1. The name of the destructor is ALWAYS the tilde (~) followed by the class name.

  2. The destructor takes no arguments and returns no value.

  3. Destructors are automatically called when an object goes out of scope.

  4. Common situations when the destructor is called automatically:

class X
  {
  public:
    X(int = 20);       //default constructor -- default capacity of 20
    ~X()               //destructor

  private:
    int capacity;
    int used;
    int *data;
  };