So I am trying to make a particle system and I need to create some Particle objects and store them in a vector to use them later. The function that does that is:
void spawnLoop( std::vector<Particle*> &particleVector ){
for (int i=0; i < 5; i++) {
particleVector.emplace_back( new Particle(400.0, 400.0, 1.0, 1.0) );
}
}
The particle class constructor looks like this:
Particle::Particle(float xPos= 400,float yPos= 400,float xVel= 0,float yVel= 0) {
float xPosition = xPos;
float yPosition = yPos;
float xVelocity = xVel;
float yVelocity = yVel;
bool dead = false;
std::cout<< "We have " << xPosition << " "<< yPosition << " "<< xVelocity << " "<< yVelocity << std::endl;
//This prints the values and they look correct
}
But if I try to loop over the vector exactly after I finish to store it , it gives me values as:1.81063e+13. I did try to research it for quite a bit but couldn't find any solution to it. EDIT:
void loopOver( std::vector<Particle*> const vec ){
for (auto i = vec.begin(); i != vec.end(); i++){
std::cout << "avem " << (*i)->getXPos() << " " << (*i)->getYPos() << std::endl;
}
}