>> There has got to be a better way.... I have read something about dynamic 
>> arrays
>> being created on the heap with the new command at runtime but I'm not sure
>> how to use them. Any thoughts?
>>     
It's ugly, but it works.

int rows = 10;
    int cols = 20;

    // Initialize
    int** array = new int*[rows];
    for ( int r = 0; r < rows; ++r ) {
        array[r] = new int[cols];
    }

    // Use it...

    // Cleanup
    for ( int r = 0; r < rows; ++r ) {
        delete array[r];
    }
    delete [] array;


It would be somewhat trivial to wrap this into a class that overrides 
operator[] to return a row accessor object that also overrides 
operator[] (to mimic the array[x][y] behavior.  It is usually just 
easier to create one large array and take care of the indexing yourself.

Andrew Harding
[EMAIL PROTECTED]
--------------------
BYU Unix Users Group 
http://uug.byu.edu/ 

The opinions expressed in this message are the responsibility of their
author.  They are not endorsed by BYU, the BYU CS Department or BYU-UUG. 
___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list

Reply via email to