I am getting a lot of errors trying to use an iterator for three dimensional vector of sets of ints. See the following code (which is just select pieces, because the whole thing is too long; I think this should be enough to see what is wrong, but let me know if it isn’t):
vector<vector<vector<set<int> > > > particles_celllist;
vector<vector<vector<set<int> > > >::iterator cell_iter;
map<int,map<int,Particle> > particle_grid;
for (cell_iter=particles_celllist[wx][wy][wz].begin();cell_iter!=particles_celllist[wx][wy][wz].end();cell_iter++)
{
double distance_to_cell=sqrt(pow(particles[*cell_iter].position().y()-(wy)*ygridlength,2)+
pow(particles[*cell_iter].position().z()-(wz)*zgridlength,2));
if (distance_to_cell<input_data.diam_large())
{
particle_grid[box_counter][*cell_iter]=particles[*cell_iter];
}
}
Note: wx, wy, wz, and box_counter are ints, ygridlength and zgridlength are doubles, and Particle::position::y (or ::z) and input_data::diam_large return doubles.
I get a multitude of errors:
no match for operator “=” in
“cell_iter=particles_celllist[wx][wy][wz].begin()”no match for operator “!=” in
“cell_iter!=particles_celllist[wx][wy][wz].end()”no match for operator “[]” whenever I used [*cell_iter] to call
something
I get the feeling like the error somehow stems from the iterator itself, but I haven’t been able to figure it out.
You want
set<int>::iterator cell_iter;. Just look again carefully at whosebegin()function you’re calling.In C++11 you would of course just have said
and never noticed that this is hard 🙂