0

Compiler warning(1): Incomplete implementation

I've compared my .h and .m files to see any inconsistencies or spelling mistakes between whats declared and implemented and can't find any.

Compiler warning(2): Incompatible integer to pointer conversion sending 'NSInteger*' (aka 'int*') with and expression of type 'int'.

I've been mucking about with asterisks for 25 minutes in all sorts of combinations and the compiler is still unhappy.

#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

Where the instance of my class is declared and initialized:

 NSInteger *rows = 7, *columns = 6, *operators = 2, *operands = 6;//compiler warning 2
 Game *game = [Game new];
 [game init:rows :columns :operators :operands];
Sean Dev
  • 1,239
  • 1
  • 17
  • 31

2 Answers2

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

rows,columns, operators, operands are of type NSInteger *. You need to allocate memory and then need to place 7,6,2,6 in the memory locations they are pointing at. In C-terms,

int *ptr = 7; // Wrong. Because, ptr is pointing no where to keep 7 in that location.
Mahesh
  • 34,573
  • 20
  • 89
  • 115
  • I had initially no asterisks, but got another error. Can you suggest an alternative way or writing it? I'm a little confused. – Sean Dev Feb 19 '12 at 16:44
0

Did you try?

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

And what is?

[Game new];

The compiler is probably expecting you to implement a function named new.

EDIT: Try removing all '*' from your NSInteger's.

Jim Rhodes
  • 5,021
  • 4
  • 25
  • 38
  • 1
    "new" is just a way of saying [[Game alloc] init] http://stackoverflow.com/questions/719877/use-of-alloc-init-instead-of-new-objective-c – Sean Dev Feb 19 '12 at 16:34
  • Sorry, I was not aware of 'new'. I always use 'alloc' and 'init'. – Jim Rhodes Feb 19 '12 at 16:37
  • I did remove the asterisks, as per the method definition and Obj-C grammar I must take in a pointer i.e. pass by reference. Otherwise I'll get an error. So what I need is: declaration and initialization of NSInteger and then a pointer to it. – Sean Dev Feb 19 '12 at 16:54