Sunday, 15 July 2012

c++ - Reading from double array of pointers - NULL -



c++ - Reading from double array of pointers - NULL -

my method replaces cells in double array _board. after replacement sets cell null.

in next phone call cell set null doesnt recognize null.

((_board[location.getx()][location.gety()]==null))

and keeps on method reading trash

whats wrong?

void board::movepiece(point location, move m) throw (gameendexception, outofboundsexception, invalidmoveexception, nonemptysquareexception) { int i,j; bool flag1,flag2; if **(_board[location.getx()][location.gety()]==null)**{ invalidmoveexception io; throw io;} if ((_board[location.getx()][location.gety()]->isvalidmove(m)==false)||(_board[location.getx()][location.gety()]->getplayernum()!=getturn())) { invalidmoveexception io; throw io;} if (_board[location.getdestination(m).getx()][location.getdestination(m).gety()]!=null) { if (_board[location.getdestination(m).getx()][location.getdestination(m).gety()]->getplayernum()==getturn()){ nonemptysquareexception io; throw io;}} point tmp=location.getdestination(m); _board[tmp.getx()][tmp.gety()]=_board[location.getx()][location.gety()]->clone(); delete _board[location.getx()][location.gety()]; _board[location.getx()][location.gety()]=null; _lastm=m; _lastp=location; flag1=false; flag2=false; (i=0;i<board_size;i++){ (j=0;j<board_size;j++){ if(_board[i][j]!=null){ if (_board[i][j]->getplayernum()==one) flag1=true; if (_board[i][j]->getplayernum()==two) flag2=true; }}} if ((flag1==false)||(flag2==false)){ gameendexception io; throw io;} }

here delete _board[location.getx()][location.gety()]; have deleted location , trying access deleted memory location.

c++

No comments:

Post a Comment