I'm not sure if there's a way to do it without using dynamic memory (i.e. the new keyword). But using dynamic memory it would look something like this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
class Foo {
public:
Foo(int **i_Tiles): Tiles(i_Tiles) {}
private:
int **Tiles;
};
int main() {
int **i_Tiles;
i_Tiles = newint*[40];
for (int i = 0; i < 40; i++) {
i_Tiles[i] = newint[30];
}
Foo foo(i_Tiles);
}
Alternatively, if you use vectors, you should be able to pass those to the constructor. Then you wouldn't need to worry about dynamic memory.
You don't need to allocate an array to be able ot make 2D that is only if you don't know the dimension at compile time. How to allocate and store the pointer for a 2D array.
int (* tiles)[30] = newint[40][30];
I hope you are freeing the memory properly btw.
I still think it would be better for the class to handle the allocation on it's own, it doesn't make sense and can cause error like if you free the array before the class is destructed.