/*
"Constructors" cannot be called explicitly as if they were regular member functions. 
They are only executed when a new object of that class is created.

You can also see how neither the constructor prototype declaration (within the class) 
nor the latter constructor definition include a return value; not even void.

The "Destructor" fulfills the opposite functionality. It is automatically called when 
an object is destroyed, either because its scope of existence has finished (for example, 
if it was defined as a local object within a function and the function ends) or because 
it is an object dynamically assigned and it is released using the operator delete. The 
destructor must have the same name as the class, but preceded with a tilde sign (~) 
and it must also return no value.

The use of destructors is especially suitable when an object assigns dynamic memory 
during its lifetime and at the moment of being destroyed we want to release the memory 
that the object was allocated.
*/

#include <iostream>
using namespace std;

class CRectangle
{
      int *width, *height;
      public:
             CRectangle (int,int);
             ~CRectangle ();

             int area() 
             {
                 return ((*width) * (*height));
             }
};

CRectangle::CRectangle (int a, int b) 
{
          width = new int;
          height = new int;
          *width = a;
          *height = b;
}

CRectangle::~CRectangle () {
          delete width;
          delete height;
}

int main () {
    CRectangle rect1 (3,4), rect2 (5,6);

    
    cout << "Area of rect1: " << rect1.area() << endl;
    cout << "Area of rect2: " << rect2.area() << endl;

    std::cin.get();
    return (0); 
}
