2012-02-19 20 views
0

编译器警告(1):完全执行未完成的实现和指针转换错误。

我比我的.h和.m文件,看看什么申报和实施,并不能找到任何之间的任何不一致或拼写错误。

编译器警告(2):指针转换发送'NSInteger *'(又名'int *')与'int'类型的表达式不兼容的整数。

我一直在用各种组合的星号25分钟,编译器仍然不高兴。

#import "Game.h" 
#import "stdlib.h" 

const int MAXRAND = 15; 
const int MAXCOL = 7; 
const int MAXROW = 9; 

NSInteger gameState[MAXROW][MAXCOL]; 
NSInteger answerBoard[MAXROW][MAXCOL]; 

@implementation Game//compiler warning 1 


-(void)init:(NSInteger*) rows: (NSInteger*) columns: (NSInteger*) operators:(NSInteger*) operands{ 
    NSLog(@"init sent"); 
    numRows = *rows; 
    numColumns = *columns; 
    numOperators = *operators; 
    numOperands = *operands; 
    //seed random number generator 

    //generate rand nums for operands 
    int operandList[numOperands]; 
    for (int i = 0; i < numOperands; i++) { 
     srandom(time(NULL)); 
     operandList[i] = (random()%MAXRAND); 
    } 
    //generate state and answer board 
    BOOL gameState[numRows][numColumns]; 
    NSInteger answerBoard[numRows][numColumns];  
    for (int i = 0; i < numRows; i++) { 
     for (int j = 0; j < numColumns; j++) { 
      gameState[i][j] = NO; 
      answerBoard[i][j] = (operandList[random()%numOperands])+ 
      (operandList[random()%numOperands])- 
      (operandList[random()%numOperands]); 
     } 

    } 
} 

-(void)updateGame:(NSInteger*)enteredNum{ 
    NSLog(@"updateGame sent"); 
    for (int i = numColumns; i > 0; i--) { 
     for (int j = numRows; j > 0; j--) { 
      if (gameState[i][j] == NO){ 
       if (*enteredNum == answerBoard[i][j]){ 
        gameState[i][j] = YES; 
       } 
      } 

     } 
    } 
} 


@end//Game 

#import <Foundation/Foundation.h> 

@interface Game : NSObject 
{ 
    NSInteger numRows, numColumns, numOperators, numOperands; 
} 

-(void)init:(NSInteger*) rows: (NSInteger*) columns: (NSInteger*) operators:(NSInteger*) operands; 
-(void)updateGame:(NSInteger*) enteredNum; 

@end 

凡我类的实例声明和初始化:

NSInteger *rows = 7, *columns = 6, *operators = 2, *operands = 6;//compiler warning 2 
Game *game = [Game new]; 
[game init:rows :columns :operators :operands]; 
+0

此致,您需要对C编程语言的基本要点进行回顾。 – ZhangChn 2012-02-19 16:37:59

+0

我试图编译你的代码在一个测试项目,它的工作..试图清除你的项目 – 2012-02-19 16:56:44

回答

0
NSInteger *rows = 7, *columns = 6, *operators = 2, *operands = 6; 

rows,columns, operators, operandsNSInteger *类型。您需要分配内存,然后需要将7,6,2,6放置在指向的内存位置。用C表示,

int *ptr = 7; // Wrong. Because, ptr is pointing no where to keep 7 in that location. 
+0

我最初没有星号,但有另一个错误。你可以提出一种替代方式或写作吗?我有点困惑。 – 2012-02-19 16:44:25

0

你试过了吗?

NSInteger rows = 7, columns = 6, operators = 2, operands = 6; 

什么是?

[Game new]; 

编译器可能期待你实现一个名为功能。

编辑: 尝试从您的NSInteger's中删除所有'*'。

+1

“new”只是一种说法[[Game alloc] init]的方式http://stackoverflow.com/questions/719877/use-of-alloc-init-instead-of-new-objective-c – 2012-02-19 16:34:03

+0

对不起,我并不知道“新”。我总是使用'​​alloc'和'init'。 – 2012-02-19 16:37:34

+0

我根据方法定义和Obj-C语法删除了星号,我必须采用指针,即通过引用。否则,我会得到一个错误。所以我需要的是:NSInteger的声明和初始化,然后是一个指向它的指针。 – 2012-02-19 16:54:02