G
Guest
Hello, all:
Just a general question that's been bothering me. Suppose I'd like to
create a 2D array of integers -- not using the vector template -- but I need
to dynamically create the array as I do not know the dimensions.
How could I do this using the "new" operator?
For instance, suppose I need to create an array of size row x column, but I
don't know the values being passed into the function...
I've tried it this way...
MyFunc(int nRow, int nCol)
{
int *array = (int *)new int[nRow][nCol];
...
delete [] array;
}
This seems to work for me, but a friend has told me this is -- perhaps --
unwise to do it that way. Any suggestions?
P.S. If there are multiple ways, could you select the way that would allow
me to access an element in the array by the following... array[1][2] =
blagh; That way I could easily access an element.
P.P.S. How would I delete the array as well?
Thank you, all.
Just a general question that's been bothering me. Suppose I'd like to
create a 2D array of integers -- not using the vector template -- but I need
to dynamically create the array as I do not know the dimensions.
How could I do this using the "new" operator?
For instance, suppose I need to create an array of size row x column, but I
don't know the values being passed into the function...
I've tried it this way...
MyFunc(int nRow, int nCol)
{
int *array = (int *)new int[nRow][nCol];
...
delete [] array;
}
This seems to work for me, but a friend has told me this is -- perhaps --
unwise to do it that way. Any suggestions?
P.S. If there are multiple ways, could you select the way that would allow
me to access an element in the array by the following... array[1][2] =
blagh; That way I could easily access an element.
P.P.S. How would I delete the array as well?
Thank you, all.