I have been stuck on this task for quite a while. I need to extend my 2d flat array to 3d. I know that doing it this way isn't the best, but I have to. I include my 2d version and my attempt at 3d. I don't exactly know what I am doing with this one.
I never liked pointers to pointers for arrays. You could flatten the entire array like this and then only need 1 delete for clean up.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
int main(){
int Height = 10;
int Width = 10;
int Depth = 10;
float* ary = newfloat[Height*Width*Depth]();
for (int k = 0; k < Depth; k++)
for (int r = 0; r < Height; r++)
for (int c = 0; c < Width; c++)
/*Init array*/
ary[k*Height*Width + r*Width + c] = 1;
delete[] ary;
return 0;
}
As you can see I am not a fan of it either :d . If I understand correctly you can't use pointer-like notation in the code you showed me ? float[2][1][12] = 5; How am I supposed to access exact array cell ?