lundi 26 juin 2017

using a std::vector

    class Particles {
     constexpr static int particleNum = 25;
constexpr static double gravity = 1.1;
std::vector<Particle> particles;
std::vector<Particle>::iterator it = particles.begin();

};

here is where I am trying to create the 25 particles that are specified above and for that i'm using the "it" iterator in the for loop which works fine but when i use the particles.at(it)function the console outputs an error code that says : error: no matching function for call to 'std::vector::at(std::vector::iterator&)' if (!particles.at(it).life){

I have tried using a simple integer for this task but then I have the .erase() function not working as it needs an it_&; just take a look:

Particles::Particles(sf::RenderWindow& renderWindow, int x, int y) {

for(unsigned int i = 0; i <= particleNum; i++){
    particles.push_back(Particle(x, y));
}

do{
    for(; it <= particles.end();){
        if (!particles.at(it).life){
            it = particles.erase(it);
        }else{
            particles.at(it).update();
            it++;
        }
        renderWindow.draw(particles.at(it).particleShape);
    }
}while(!particles.empty());
// to change later for different effects:

}

Aucun commentaire:

Enregistrer un commentaire