Use classes as arrays in c++
<p><strong>What i want to do:</strong>
I want to know how to use classes as a kind of 'built-in' arrays in C++(C is also acceptable). So, basically I want to be able to do this:</p>

<pre><code>array1d rows(5); 
//an integer array of length 5 - iniatilized to 0 upon instantiation.
//rows can be imagined as this: [ 0, 0, 0, 0, 0 ]



array1d x(1), y(2), z(3);
array2d cols(3);
cols[0] = x;
cols[1] = y;
cols[2] = z;

//an array of array of integers [ [x] [y] [z] ]
//where x, y and z are of type array1d, so here is what it would like:
//if x = 1, y = 2, z = 3
//[ [0], [0, 0], [0, 0, 0] ]

array3d depth(2); 

//an array of array of array of integers [ [cols] [cols] ]
//where cols is of type array2d, so when expanded it would like:
//[ [ [0], [0, 0], [0, 0, 0] ]
//  [ [0], [0, 0], [0, 0, 0] ] ]
</code></pre>

<p><strong>What I have so far</strong></p>

<pre><code>using namespace std;

class array3d;
class array2d;

class array1d//works exactly the way i want it to 
{
    int len;
    int *data;
public:
    array1d (int size){
        data = new (nothrow) int[size];

        if (data != 0){
            len = size;

            for (int i = 0; i&lt;len; i++){
                data[i] = -1;
            }
        }
    }

    ~array1d (){
        delete data;
    }


    void print(){
        for (int i = 0; i&lt;len; i++){
                cout &lt;&lt; data[i] &lt;&lt; " ";
            }
        cout &lt;&lt; endl;
    }


    int operator[] (int index){
        if (index &gt;= 0 &amp;&amp; index &lt;= len){
            return data[index];
        }
    }


    friend class array2d;
};

class array2d//this is what needs changing
{
    int len;
    array1d *data;
public:
    array2d (int size_dim1, int size_dim2){
        data = new (nothrow) array1d[size_dim1]; //i think the problem is here

        if (data !=0){
            len = size_dim1;
            for (int i = 0; i &lt; len; i++){
                data[i] = array1d(size_dim2);
            }
        }
    }
    ~array2d (){}

    void print(){
        for (int i = 0; i &lt; len; i++){
            data[i].print();
        }
    }

    array1d operator[] (int index){
        return data[index];
    }

    friend class array3d;   
};

class array3d//dont even know how to get this one started
{
    array3d (int size_dim1, int size_dim2, int size_dim3){
             data = new (nothrow) array2d[size_dim2, size_dim3]; 

        if (data !=0){
        len = size_dim1;
            for (int i = 0; i &lt; len; i++){
                data[i] = array2d(size_dim2, size_dim3);
            }
        }
            }
    ~array3d (){}
    //overload [] operator

private:
    int len;
    array2d *data;
};
</code></pre>

<p>I also want to be able to add more classes to accomodate for a possible 4 dimension such that i dont have to customize each and every time i add another class.</p>
