I am still new to C++, please excuse any silly mistakes i make.
I'm trying to make a simple game where i use 2D arrays as maps.
To make multiple maps I'm trying create a pointer to a 2D array. This is an example of what I'm trying to do:
This code compiles, but when run it crashes.
I tried looking this up on Google and forums, but all the questions i found involve matrices which is very confusing for me.
Any help would be appreciated :)
In line 4 change char * Map[20][20]; to char** Map;
in line 19, change * Map[20][20] = map1[20][20]; to Map = map1;
The fact that you have char* makes line 24 work, but if you had used any other type, you'd need to use a nested loop to print each element of the array:
1 2 3 4 5 6
for (int y = 0; y < 20; y++)
{
for (int x = 0; x < 20; x++)
std::cout << Map[y][x];
std::cout << std::endl;
}