the trick is that you need to get a reference to the object in the vector, if you do:
vector<particle> particles;
particles.resize(20);
for ( auto p : particles) {
p.setup(posX, posY, width, heiht);
}
you are making a copy and calling setup on that copy, if you want to modify the original in the vector the correct syntax is:
vector<particle> particles;
particles.resize(20);
for ( auto & p : particles) {
p.setup(posX, posY, width, heiht);
}
note the &
between auto
and p
that makes p
a reference to the object in the vector instead of a copy.