+ 2

Need help with memory management in C++!!

Hi, I just completed the C++ course and started learning SFML and I tried to make a very basic particle system and it works but it slows down with time. I made a Particle class and at the main function a created a vector of Particles to stack them up , but at the stage of deleting the particles that fade out (for optimization) using the "erase" method it gives me error . Main.cpp: https://code.sololearn.com/cANHJju2fj63/#cpp Particle.h: https://code.sololearn.com/c2cobfwktEJT/#cpp Particle.cpp: https://code.sololearn.com/comloWN8Reug/#cpp

24th Oct 2020, 6:03 PM
Hilal El Mehdi
Hilal El Mehdi - avatar
1 Answer
+ 3
The erase() method needs to rearrange the following elements in the vector, and for that it needs an assignment operator. The problem is that default assignment operators are deleted implicitely in some cases, among them the presence of a non-static reference member in the class. This rule is triggered by the "window" member in your Particle class, resulting in a deleted assignment operator. You can fix this by either using a pointer instead of a reference for "window", or by explicitely implementing the assignment operator yourself.
24th Oct 2020, 8:00 PM
Shadow
Shadow - avatar