Initializing an array of classes

Aug 13, 2012 at 3:46pm
Hi, I am trying to create a particle engine. This class ParticleEngine contains a pointer to a specified number of particles, then it will go through and doo all of the math to initialize them. I am trying to create a new array of particles like
 
Particles = new Particle[AmountOfParticles];

The problem is that the class Particle does not have a constructor with no parameters (it is actually Particle(float, Color&,Mass*)) So how would i make all of the particles?
Aug 13, 2012 at 3:56pm
http://www.cplusplus.com/forum/general/18926/

That thread indicates that you'll have to provide a default and then loop though again to initialise.
Last edited on Aug 13, 2012 at 3:57pm
Aug 13, 2012 at 4:05pm
closed account (1yR4jE8b)
You could use "placement new" and allocate the memory, and then loop over the array to initialize them.

http://en.wikipedia.org/wiki/Placement_syntax
Topic archived. No new replies allowed.