Icomplete实现和指针转换错误。

时间:2012-02-19 16:13:26

标签: objective-c ios5 compiler-warnings

编译器警告(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];

2 个答案:

答案 0 :(得分:0)

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

rows,columns, operators, operands属于NSInteger *类型。您需要分配内存,然后需要将7,6,2,6放在它们指向的内存位置。用C语言,

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

答案 1 :(得分:0)

你试过吗?

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

那是什么?

[Game new];

编译器可能希望您实现名为 new 的函数。

编辑: 尝试从NSInteger中删除所有“*”。