/*
It is perfectly valid to create pointers that point to classes. We simply have to 
consider that once declared, a class becomes a valid type, so we can use the class 
name as the type for the pointer. For example:

"CRectangle * prect;"

is a pointer to an object of class CRectangle. As it happened with data structures, 
in order to refer directly to a member of an object pointed by a pointer we can
use the arrow operator (->) of indirection. 
*/

#include <iostream>
using namespace std;

#define Dimension   10

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

             void set_values (int a, int b)
             {
                  width  = a;
                  height = b;
             }
                          
             int area ()
             {
                 return (width*height);
             }
};

CRectangle::CRectangle () 
{
          width  = 0;
          height = 0;
}

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

int main () 
{
    CRectangle rect(3,4);
    CRectangle *ptr;
    CRectangle *rects = new CRectangle[Dimension];
            
    cout << "Area of rect: " << rect.area() << endl << endl;
    ptr = &rect;
    cout << "Area of rect: " << ptr->area() << endl << endl;
    
    for (int i=0; i<Dimension; i++)
    {
        rects[i].set_values(i,2*i+1);
        cout << "Area of rect[" << i <<"]: " << rects[i].area() << endl;
    }
    
    delete[] rects;
    
    std::cin.get();
    return (0); 
} 
    
