A 2D array is not a pointer to a pointer. Arrays and pointers have fundamentally different types in C and C ++. An array decays to a pointer to its first element (hence, a frequent confusion between them), but it only decays to the first level: if you have a multidimensional array, it decays to a pointer to an array, not a pointer to a pointer.
The correct declaration of get_ghost_moves is to declare it as returning a pointer to an array:
static MoveDirection ghost_moves[GHOSTS_SIZE][4]; // Define get_ghost_moves to be a function returning "pointer to array 4 of MoveDirection" MoveDirection (*get_ghost_moves())[4] { return ghost_moves; }
The syntax syntax is extremely confusing, so I recommend making a typedef for it:
// Define MoveDirectionArray4 to be an alias for "array of 4 MoveDirections" typedef MoveDirection MoveDirectionArray4[4]; MoveDirectionArray4 *get_ghost_moves() { return ghost_moves; }
source share