void ParticleGeneratorController::generate() {
for( unsigned i = 0; i < generators.size(); i++) {
ParticleGenerator generator = *generators[i];
generator.update();
}
}
Seems to call a copy constructor or something, but I didn’t define one. I only have an explicit default constructor.
https://github.com/ChrisLundquist/Waveform/blob/master/src/models/particle_generator.h
Given my above code, by test fails. https://github.com/ChrisLundquist/Waveform/blob/master/spec/controllers/particle_generator_controller_spec.cpp#L21
When written as
void ParticleGeneratorController::generate() {
for( unsigned i = 0; i < generators.size(); i++) {
generators[i]->update();
}
}
The test passes.
Why is the copy constructor called in the first implementation? How is it generated by the compiler?
This line causes the copy:
If no copy constructor (or assignment operator) is explicitly specified, the compiler automatically generates one. If you wish to prevent copying of an object you can declare, and not define, the copy constructor and assignment operator as
private: