int main()
{
cout << "Welcome to the Maze Game!\n";
cout << "(press ENTER to start)";
cin.get();
system("cls");
bool maze[ROWS][COLS];
loadMaze(maze);
bool map[ROWS][COLS] = {};
int
x = 0,
y = 0;
map[y][x] = 1;
printMap(map, x, y);
函数定义
我如何定义以便将 map 用作参数。
void printMap(bool array[][ROWS][COLS])
{
// DECIDE BETWEEN:
// print '.' if the user has been at spot before
// print 'x' character (NOT the value of variable x) to MARK the user's current position
// print '#' for spots the user has NOT been yet
}
最佳答案
你可以通过map
进入printMap
作为:
void printMap(bool map [ROWS][COLS])
或
void printMap(bool map [][COLS])
如果您想从 2D 制作 3D 阵列 map
, 您可以在 printMap
中定义一个新的 3D 数组并使用来自 map
的数据.但是,我强烈建议您使用 std::vector
而不是原始数组,因为它们更易于使用。有兴趣者,here是关于 std::vector
的一些文档.
关于c++ - 如何在使用 2d 数组作为参数时创建 3d 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51460942/