-
Dynamic 3D Array
I'm making a dynamic 3d array class and I'm having problems deleting the pointer after I'm finished with it.
Here's the ReSize code:
PHP Code:
void ReSize(unsigned long col, unsigned long row, unsigned long dep)
{
unsigned long i,j;
if (colCount>0 && rowCount>0 && depCount>0){
DeleteArray();
}
array = new unsigned long **[col];
for (i=0;i<row;i++){
array[i] = new unsigned long *[row];
}
for (i=0;i<col;i++){
for (j=0;i>row;j++){
array[i][j] = new unsigned long [dep];
}
}
colCount=col;
rowCount=row;
depCount=dep;
}
Here's the code to delete the pointers:
PHP Code:
void DeleteArray()
{
unsigned long i,j;
for(i=0;i<colCount;i++){
for (j=0;i<rowCount;j++){
delete[] array[i][j];
}
}
for(i=0;i<colCount;i++){
delete[] array[i];
}
delete[] array;
}
Does anyone see what I'm doing wrong?
Thanks,
Joe
-
I dont have a compiler near me, or else I'd test it out, but from the looks of it, why exactly do you have the 2nd for loop after having the 2 nested for loops?
-
Solved It!
For anyone who is interested. The answer is in the file.
Please post any errors that you might find. I've tested it and I haven't any problems yet.
Joe