Hi everyone. I've recently started doing some work with vectors, and I'm a little confused so I just have a few questions on this program I'm writing. So the program is supposed to create an endless loop of little particle bouncing around inside of a little box. I was able to do it pretty eaily for just one particle, but I need to use vectors in order to create more particles. You'll notice here:
vector<Particle*>Ball;
for(i;i<10;i++)
{
Ball.push_back(new Particle());
}
//Particle* Ball1=new Particle();
that I was trying to figure it out a bit, and commented what I was using to make it work with just one particle. Also another more broad question is that I was wondering if anyone could explain to me the whole pass by reference and pass by value thing? I don't really understand what it does, how it works, or what it's used for? Thanks! And sorry if I posted this maybe a little weird it's my first post here!
Line 15,99: Do not call srand() within a loop or a random number function. srand() sets the RNG to a particular starting point. Calling srand() repeatedly can cause the RNG to return the same random numbers. srand() should be called ONCE at the beginning of main(). http://www.cplusplus.com/reference/cstdlib/srand/
Pass by value: The function gets a copy of the argument. Any changes made to the argument within the function are not reflected in the caller's copy of the argument.
Pass by reference. The function references the caller's instance of the argument. Any changes made to the argument are reflected in the caller's instance of the argument.
Pass by reference is preferred for large objects as it avoids creating a copy of the argument on the stack.