Objective-C Implementing a class (Initialization of array) -



Objective-C Implementing a class (Initialization of array) -

my initialization of array getting weird error. i'm missing? error @ gameboard array.

@implementation tictactoe - (id)init { self = [super init]; if (self) { gameboard [3][3] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}; // error saying: "expected expression" turn = 1; winner = 0; cellschosen = 0; } ...

you have gameboard declared in @interface tictactoe, right? cannot utilize c array initialization syntax, because array initialized. unfortunately c doesn't provide shortcut assign arrays, should create temporary array initialized values , utilize memcpy re-create elements array.

... if (self) { int tmpgameboard[3][3] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}; nsassert(sizeof(tmpgameboard) == sizeof(gameboard), @"gameboard not 3x3 array"); memcpy(gameboard, tmpgameboard, sizeof(tmpgameboard)); ...

nsassert used create sure haven't changed array size in interface , forgot update initialization (it improve utilize compile time assertion instead of nsassert, that's topic).

objective-c

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -