I have a variable in class declared as compile-time constant with known size:
static const int array[5][5]; // constants initlialised in another place
And a function that returns it virtually:
virtual const int** getArray() { return array; }
How to get this array with this method, and cast it to fixed-size array, not pointers-based, so I can use it like cout << data[2][2] ?
Sample that dosn't compile:
const int[5][5] data = object->getArray();
cout << data[2][2];
Sample that compiles but crashes application:
const int** data = object->getArray();
cout << data[2][2];
Note: one solution is to create typedef arr[5] and declare methods with arr* but i don't want to create a typedef for each compile-time size wich I use like typedef arr5[5]; typedef arr10[10] etc. I'm looking for something more like:
const int(*)[5] data = object->getArray(); // won't compile, example only
Let's assume that compile-time constant array is loaded with dynamic DLL and is already in memory, is it possible to use this data as array without allocating new memory and populating it from compile-time constants?
const int**is not the same as a pointer to an array with two dimensions. It doesn't work like that. You can't cast it. You could cast aconst int*toconst arr *if you wanted, wherearris a typedef.getArrayfunction makes no sense and isn't valid C++.