René Olsthoorn's techtips
Technical tips for various products and programming languages
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.
Geen opmerkingen:
Een reactie posten
Nieuwere post
Oudere post
Homepage
Abonneren op:
Reacties posten (Atom)
Geen opmerkingen:
Een reactie posten