[C++] How do i initialize the size of a 3D Array in c++ in a method

Hi. I want to store my block actor data in a 3D array. So i can just call blocks[x][y][z] and get the block at the give coordinate. Atleast this worked in java but not in c++. Is there a way to store my 3D block data in a 3D Array where i can set the size of it in a method ?

Yes there is but the question is how you are going to manage memory ? Do you want an dynamic array allocated on heap or your array size will be fixed for the entire run time and allocated on stack ? Another thing is if you want to store the actual data in array or just ponters to data or even the references ?

Ok so you declare a 3d array first and specifying the size in subscript operator so to stor a pointers you wold do it like this

MyDataType* mydata3dArray[sizeX][sizeY][sizeZ];

//and use it this way

mydata3dArray[indexX][imdexY][indeZ] = Data;

Note that the size must be known at compile time and must be a constant value

i want to store Pointer refs to blocks at the given x,y,z location. The Array will have a fixed size because of the level size.

So i cant have something like this ?
Like dynamicly change the size of the array ? Like when i am loading a new level in?

int[][][] array;

public void main()
{
     int x = 5;
     array = new int[x][x][x];
}

No arrays in c++ are different from c# you will have to declare array as a pointer to pointer to poiner and allocate memory your self for dynamic arrays

thats sad. But the link you send me should do the trick. Thanks for your help

No is not do your lessons ! Memory management is very important. c++ is unmanaged you have to code stuff yourself if you want array like this than you can use a class templates to develop a type witch will behave jus as you want. it ain’t that hard I though is something hard to do but guess what I’ve ended up developing entire memory management system for my portfolio project including dynamic allocation size pool, fixed allocation size pool, memory manager with leak tracking system and entire allocation inteface for win32 platform, actually I’ve deveooped entire game framework including game AI system and procedurall generation algorithm you can check part of my progress here