I am looking for a way to access a multidimensional Array that is passed via pointer. I followed the question here (Create a pointer to two-dimensional array) to create my array and a pointer to it. I could even pass the pointer to the function, but I can't use the pointer to access the array values. What's the correct way to access the values inside the function.
main.cpp:
MyArrayGenerator theArrGen = MyArrayGenerator();
const int size = 9;
int generatorArray[size][size][10];
theArrGen.generateArray(size, generatorArray[size][size+1]);
The method in my class:
void MyArrayGenerator::generateArray(int size,int* pointerToMultiDimArr)
{
int height = size + 1;
// this ptr points to the array address
int* ptr = pointerToMultiDimArr;
// not working:
ptr[1][1][1] = 123;
}
this throws the compiler error https://msdn.microsoft.com/de-de/library/fhexbxk9.aspx wich means that the pointer is not declared as array.
I guess my method argument needs to change since it wants a pointer and does not know that it will be an array. My question is: How should the method argument look like and how do I access the array in my method after that. Later on I want the user to input the size of the multidimensional array and
const int size = 9;
is just a placeholder