2011-07-15 49 views
2

h文件傳遞兩個維C風格數組目標C方法

@interface GameState :NSObject{ 
int SymbolsPositions[3][5]; 
} 
-(void)SaveCurrentGameState:(int **)Array; 
@end 


@interface GameViewController : UIViewController 
{ 
    ... 
int sequence_after_spin[3][5]; 
    ... 
} 
-(Void)AMethod; 
@end 

.m文件

@implementation GameState 
-(void)SaveCurrentGameState:(int **)Array 
{ 
    for(int i = 0;i<5;i++) 
    for(int j = 0;j<3;j++) 
     NSLog(@" %d",Array[j][i]); 
} 
@end 


@implimentation GameViewController 
-(void)AMethod 
{ 
    [instanceOfGameState SaveCurrentGameState:sequence_after_spin]; 
    } 
@end 

當過amethod方法被調用的iget應用程序崩潰以下警告

warning: incompatible pointer types sending 'int [10][5]' to parameter of type 'int **' [-pedantic] 
+0

也添加崩潰日誌。崩潰可能是由於不同的原因。 –

+0

'int **'和'(* int)[5]'是不一樣的 – user102008

回答

5

Th e參數需要採用int [] [5]的數組,因爲編譯器需要知道列的數量才能正確識別成員的位置。如果您始終採用相同大小的數組,您也可以指定int [10] [5]作爲參數類型。

0

雖然可能有其他錯誤的,一個我看到的是

for(int i;i<5;i++) 
    for(int j;j<3;j++) 
     NSLog(@" %d",Array[j][i]); 

你是不是一個初始值設定爲ijij可以是任何垃圾值。

for(int i = 0;i<5;i++) 
    for(int j = 0;j<3;j++) 
     NSLog(@" %d",Array[j][i]);