The first line of the body of your for loop dereferences the pointer array2d
(using the square bracket operator) before you've allocated any memory for it, or initialized it.
To avoid this issue, you'll have to allocate the first dimension of your array before entering your for loop. Once you've allocated this array of pointers, you can then allocate BOARD_DIMENSIONS
arrays of short
s and store the pointers to them in the elements of the first array.
Something like:
short** array2d = new short*[BOARD_DIMENSIONS];
for (size_t u = 0; u < BOARD_DIMENSIONS; ++u)
{
array2d[u] = new short[BOARD_DIMENSIONS];
// You could then use memset to initialize the array, or
// use a for loop, like in your example:
for (size_t v = 0; v < BOARD_DIMENSIONS; ++v)
{
array2d[u][v] = 0;
}
}
Make sure when you're done with the memory that you release it properly, using operator delete []