-3
私は既にこの質問の回答を得ています。この問題を理解するためにC++コンパイルエラー: 'printMaze(int const(*)[16]、int、int)'への参照を未定義にし、Id終了ステータスを1つ返しました。
何らかの理由で、私がプログラムをコンパイルしようとすると、コンパイラはエラーを 'printMaze(int const(*)[16]、int、int)'への参照を定義解除し、状態。 これはあなたの宣言であるあなた
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
void printMaze(const int maze[][16], int xLoc, int yLoc);
int mazeTraverse(int maze[][16], int xLoc, int yLoc, int facing);
int main()
{
int maze[ 9 ][ 16 ] = {
{42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42},
{42, 0, 0, 0, -1, 0, 0, 0, -1, 0, -1, 0, 0, 0, 0, 42},
{42, -1, -1, 0, -1, -1, -1, 0, -1, 0, -1, 0, -1, -1, -1, 42},
{42, -1, -1, 0, -1, -1, -1, 0, -1, 0, -1, 0, -1, -1, -1, 42},
{42, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, 0, 42},
{42, 0, -1, -1, -1, 0, -1, 0, -1, 0, -1, 0, -1, -1, 0, 42},
{42, 90, -1, -1, -1, 0, -1, 0, -1, 0, -1, 0, -1, -1, 0, 42},
{42, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1, -1, 80, 42},
{42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42}
};
int success = 0;
success = mazeTraverse(maze, 7, 14, 1); // Call function to move through the maze, assign returned value to success.
if (success == 1) // If success is equal to 1...
cout << "Congratulations! The maze has been solved.\n"; // ...output congratulations...
else // ...else...
cout << "Unfortunately the maze has not been solved correctly.\n"; // ...output failed message.
return 0; // End program.
}
// print the current state of the maze
void printMaze(const char maze[][ 16 ], int xLoc, int yLoc)
{
// nested for loops to iterate through maze
for (int x = 0; x < 9; ++x)
{
for (int y = 0; y < 16; ++y)
if ((x == xLoc) && (y == yLoc))
cout << 'X' << ' ';
else
cout << maze[ x ][ y ] << ' ';
cout << '\n';
} // end for
cout << "\nHit return to see next move\n";
cin.get();
} // end function printMaze
// Traverse through the maze one square at a time
int mazeTraverse(int maze[][16], int xLoc, int yLoc, int facing)
{
int success = 0;
maze[xLoc][yLoc] = 1; // Mark current location in the maze.
printMaze(maze, xLoc, yLoc); // Call function to display maze with current location marked.
while (success == 0) // While success is not equal to 0...
{
if ((xLoc == 6) && (yLoc == 1)) // If current location is the exit of the maze...
{
success = 1; // ...set success to 1.
}
else if (facing == 0) // Else if facing up...
{
if (maze[xLoc][yLoc+1] == 0) // ...check square to the right for valid move...
{
success = mazeTraverse(maze, xLoc, yLoc+1, 1); // Move to the right.
}
else if (maze[xLoc-1][yLoc] == 0) // ...check square above for valid move...
{
success = mazeTraverse(maze, xLoc-1, yLoc, 0); // Move up.
}
else if (maze[xLoc][yLoc-1] == 0) // ...check square to the left for valid move...
{
success = mazeTraverse(maze, xLoc, yLoc-1, 3); // Move to the left.
}
else // If nowhere to go...
return 0; // ...close recursion to the previous junction.
}
else if (facing == 1) // If facing right...
{
if (maze[xLoc+1][yLoc] == 0) // ...check square below for valid move...
{
success = mazeTraverse(maze, xLoc+1, yLoc, 2); // Move down.
}
else if (maze[xLoc][yLoc+1] == 0) // ...check square to the right for valid move...
{
success = mazeTraverse(maze, xLoc, yLoc+1, 1); // Move right.
}
else if (maze[xLoc-1][yLoc] == 0) // ...check square above for valid move...
{
success = mazeTraverse(maze, xLoc-1, yLoc, 0); // Move up.
}
else // If nowhere to go...
return 0; // ...close recursion to the previous junction.
}
else if (facing == 2) // If facing down...
{
if (maze[xLoc][yLoc-1] == 0) // ...check square to the left for valid move...
{
success = mazeTraverse(maze, xLoc, yLoc-1, 3); // Move to the left.
}
else if (maze[xLoc+1][yLoc] == 0) // ...check square below for valid move...
{
success = mazeTraverse(maze, xLoc+1, yLoc, 2); // Move down.
}
else if (maze[xLoc][yLoc+1] == 0) // ...check square to the right for valid move...
{
success = mazeTraverse(maze, xLoc, yLoc+1, 1); // Move to the right.
}
else // If nowhere to go...
return 0; // ...close recursion to the previous junction.
}
else if (facing == 3) // If facing left...
{
if (maze[xLoc-1][yLoc] == 0) // ...check square above for valid move...
{
success = mazeTraverse(maze, xLoc-1, yLoc, 0); // Move up.
}
else if (maze[xLoc][yLoc-1] == 0) // ...check square to the left for valid move...
{
success = mazeTraverse(maze, xLoc, yLoc-1, 3); // Move to the left.
}
else if (maze[xLoc+1][yLoc] == 0) // ...check square below for valid move...
{
success = mazeTraverse(maze, xLoc+1, yLoc, 2); // Move down.
}
else // If nowhere to go...
return 0; // ...close recursion to the previous junction.
}
} // ...end while loop.
return success; // Return value of success.
}
エラーは...ですか? – Danh
エラー:Idが1の終了ステータスを返しました – Developer
私は完全なエラーを意味します – Danh