Skip to main content
1 of 2

This block of code will be copying each object of type Charge for every iteration and assigning to the variable called charge.

  for(auto charge: this -> distribution)
  {
      charge.render(*this -> window);
  }

You need to change auto to auto& because you want to use a reference to the object itself not a copy of it. In most cases, this is the right approach in range-based for loops.

  for(auto& charge: this -> distribution)
  {
      charge.render(*this -> window);
  }