donderdag 25 juli 2013

C++ copy-by-value problems

In C++, copy-by-value is default. If you do the following:

Node n = grid[i][j];
n.x = 100;

you have a new object called n, which is not the same object as grid[i][j].
To solve the situation, you can do:

Node& n = grid[i][j];
n.x = 100;

The &n is the same as &grid[i][j] in this case.