✔ 最佳答案
I think you're trying too hard.
In C++, you use dynamic allocation (e.g. using malloc or the "new" keyword) to allocate memory inside functions. though the local pointer might hold them is destroyed, the memory stays allocated, so unless you manage the memory somewhere else, you should manage it inside your class.
The solution for your problem should take into considerations the following factors -
Is the size of the array (or any of its dimensions) fixed after initialization?
What kind of access do you need? (arbitrary/random, iterative along one dimension, a "walk" between adjacent cells, etc.).
For the simplest case, when the array has fixed dimensions, the easiest solution would be to allocate one consecutive block of memory, and convert the triple (x-y-z) index into one linear index.
In two dimensions. Think of a 2-dimension array as a concatenation of 1-dimension arrays, and a 3-dimension array as a concatenation of 2-dimension arrays. The index conversion is fairly easy -
For 2 dimensions - say you have N rows and M columns, and you want to access the 5th column of the 3rd row, the linear index is 3*M+5
I'll let you figure out for yourself how to extend it to 3 dimensions.