An array is not a pointer.
On the left you have a pointer to pointers to pointers to integers.
On the right, you are returning a pointer to array of arrays of pointers to integers.
These types do not match.
Now, in C/C++ pointers and arrays are confusing. This is because arrays decay into pointers at the drop of a hat.
Your three star variable can be used to store a jagged array of pointers.
To make a 2d jagged array, you need to both allocate the array of pointers foe the first dimension, then one or more buffers to store the elements. By far the easiest way to do this is a vector of vectors.
Of for whatever reason you insist on using raw pointers, it looks like:
template<class T>
T*const* make_packed2d( std::size_t x, std::size_t y ){
T* inner = new T[x*y];
T**outer = new T*[x];
for (std::size_t i=0; i!=x;++i){
outer[i]=inner+(i*y);
}
return outer;
}
template<class T>
void free_packed2d(T*const* ptr){
if(!ptr) return;
delete[] ptr[0];
delete[] ptr;
}
or similar.
If your array is not jagged, you can do it in one line, but it does not get stored in a three star variable. In the non jagged case, the size of one of the dimensions gets stored in the type.
This type is not compatible with a pointer pointer pointer.
uint64_t *(*ptr)[64] = new uint64_t*[2][64];
the left is the type of variable that can store the new expression you used. I simply copied it out of the error message, and added the variable name in the appropriate spot.
You'll note that the "64" size is hard coded into the variable type. A "jagged" array in C/C++ is an array of pointers to arrays, while a N dimensional array is an array of arrays, where the sub-arrays are fixed in size.
The advantage of "jagged" is that you don't need to know the sub-dimensions as part of the type. The advantage of the non-jagged is that the memory is contiguous, and you don't need the sub-buffers pointing to the sub-arrays.
My make_packed2d
attempts to split the difference; it has a sub-buffer pointing to the sub-arrays, but it makes the actual data contiguous and has the sub-buffer pointing to sub-sections of the sub-arrays.