我正在嘗試編寫井字遊戲,但我收到編譯器錯誤。有3個與TTT::whoWins
函數相關的錯誤。任何人都可以幫助我,或者指引我走向正確的方向。如何將託管數組傳遞給函數?
錯誤是:
Error 2 error C2664: 'TTT::checkColumn' : cannot convert parameter 1 from 'cli::array<Type,dimension> ^' to 'int [][3]' C:\Users\Grunt\Desktop\tictactoe game\tictactoe game\TTT.cpp 59
Error 3 error C2664: 'TTT::checkDiagonal' : cannot convert parameter 1 from 'cli::array<Type,dimension> ^' to 'int [][3]' C:\Users\Grunt\Desktop\tictactoe game\tictactoe game\TTT.cpp 59
Error 1 error C2664: 'TTT::checkRow' : cannot convert parameter 1 from 'cli::array<Type,dimension> ^' to 'int [][3]' C:\Users\Grunt\Desktop\tictactoe game\tictactoe game\TTT.cpp 59
代碼如下所示:
TTT::TTT()
{
matrix = gcnew array <int,2>(3,3);
}
bool TTT::isaTie()
{
return 0;
}
bool TTT::isaTie2()
{
return 0;
}
int TTT::whoWins()
{
if((checkRow(matrix,ROW_SIZE))==1 || (checkColumn(matrix,COLUMN_SIZE))==1 || (checkDiagonal(matrix,ROW_SIZE))==1)
return 1;
else
return 0;
}
bool TTT::checkRow (int mat[][COLUMN_SIZE], int ROW_SIZE)
{
int row1 = mat[0][0] + mat[0][1] + mat [0][2];
int row2 = mat[1][0] + mat[1][1] + mat [1][2];
int row3 = mat[2][0] + mat[2][1] + mat [2][2];
if (row1 == 0 || row2 == 0 || row3 == 0)
{
return 1;
}
else if (row1 == 3 || row2 == 3 || row3 == 3)
{
return 1;
}
else
return 0;
}
bool TTT::checkColumn (int mat[][COLUMN_SIZE], int ROW_SIZE)
{
int col1 = mat[0][0] + mat[1][0] + mat [2][0];
int col2 = mat[0][1] + mat[1][1] + mat [2][1];
int col3 = mat[0][2] + mat[1][2] + mat [2][2];
if (col1 == 0 || col2 == 0 || col3 == 0)
{
return 1;
}
else if (col1 == 3 || col2 == 3 || col3 == 3)
{
return 1;
}else
return 0;
}
bool TTT::checkDiagonal (int mat[][COLUMN_SIZE], int ROW_SIZE)
{
int diag1 = mat[0][0] + mat[1][1] + mat [2][2];
int diag2 = mat[2][0] + mat[1][1] + mat [0][2];
if (diag1 == 0 || diag2 == 0)
{
return 1;
}
else if (diag1 == 3 || diag2 == 3)
{
return 1;
}else
return 0;
}
我試過了,它只是給了我更多的錯誤。你能給我更詳細的信息嗎? – 2012-03-19 14:09:42
我建議你閱讀:http://www.codeproject.com/Articles/7704/Arrays-in-C-CLI,應該解決你的問題。 – Azrael3000 2012-03-19 14:26:18