How do I return a multidimensional array stored in a private
field of my class?
class Myclass {
private:
int myarray[5][5];
public:
int **
How do I return a multidimensional array hidden in a private field?
If it's supposed to be hidden, why are you returning it in the first place?
Anyway, you cannot return arrays from functions, but you can return a pointer to the first element. What is the first element of a 5x5 array of ints? An array of 5 ints, of course:
int (*get_grid())[5]
{
return grid;
}
Alternatively, you could return the entire array by reference:
int (&get_grid())[5][5]
{
return grid;
}
...welcome to C declarator syntax hell ;-)
May I suggest std::vector
or boost::multi_array
instead?