Passing dynamic array by reference?

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
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?
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
Topic archived. No new replies allowed.