Feb 14, 2013 at 2:00pm UTC
So, in board.h I have:
1 2 3 4 5 6
class Tile
{
public :
enum State { Empty, Player, Opponent };
State state;
};
in go.h I have:
void OpponentTurn(Board, Board::Tile[]);
and in go.cpp I have:
go.OpponentTurn(board, tile);
and
1 2 3 4 5 6 7 8
void Go::OpponentTurn(Board board, Board::Tile *tile)
{
int input1, input2;
/* code */
tile[input1+(input2*board.Size)].state=Board::Tile::Opponent;
}
Now, how do I have the tile.state stay Board::Tile::Opponent when I come out of the function?
Thanks
Last edited on Feb 14, 2013 at 2:06pm UTC
Feb 14, 2013 at 2:45pm UTC
It is passed by pointer already, you already manipulate existing memory. Passing the pointer by reference would allow you to assign a new value to the pointer, but in this case it is not what you want to do. Your code already has the behavior you want, are you getting unexpected results?
Feb 14, 2013 at 2:57pm UTC
Once I get out of the function, I believe tile[input1+(input2*board.Size)].state has gone back to Board::Tile::Empty. Am I wrong?
If I am wrong, then the problem's got to be something else :/
Thanks
Edit: I found the problem. It was somewhere else in the code, thanks.
Last edited on Feb 14, 2013 at 3:04pm UTC