2012-01-20 7 views
2

Objective-Cで2次元配列を渡す方法を理解できません。私が間違っていることについて私はいくつかの助けを愛するだろう。私はというエラーを取得し続ける:Objective-Cで2次元配列を渡すにはどうすればよいですか?

がここにdisplayGameBoard "

のためのタイプが競合することは私のコードです:

//protype 
void displayGameBoard (NSInteger) 

//int main function 
NSInteger gameBoard [3][3] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; // declaring 
// caller  
    displayGameBoard (gameBoard [3][3]) 


// function receiving data from array 
void displayGameBoard (NSInteger gameBoard [3][3]) 
{ 
    // rest of my code 

} 

答えて

1

実際にそれがCで2次元配列と全く同じです言語。

関数の定義は正常ですが、宣言が正しくありません。定義にあるとおり、

void displayGameBoard (NSInteger[3][3]); 

である必要があります。

0

それは2次元配列なので、ように初期化する必要があります。

NSInteger gameBoard [3][3] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}; 
1

あなたはあなたの関数を呼び出しているときに問題があります。

displayGameBoard (gameBoard [3][3]) 
gameBoard [3][3]

を書き込むと4列の4行目の要素を意味します。あなたがそうするときNSIntergerを得る。しかし、displayGameBoardは、NSIntegerまたはNSInteger *へのポインタを想定しています。したがって、コンパイラは型の不一致を見てエラーを引き起こしています。

これを修正する方法は

//protype 
void displayGameBoard (NSInteger[3][3]) // Must have the same argument type in your pro to type as the implementation. 

//int main function 
NSInteger gameBoard [3][3] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; // declaring 
// caller  
displayGameBoard (gameBoard) // Place in the entire array not just an element 


// function receiving data from array 
void displayGameBoard (NSInteger gameBoard [3][3]) 
{ 
    // rest of my code 

} 
です
関連する問題