I am fairly new to c++, but had a question about vectors. My goal is to remove an element from the vector using erase once I hit my out of bounds condition. This all seems to work fine, except that when I call erase, it will be pointing to the first element, but delete the last. Basically, the loop will continue to iterate and delete every element out of my vector. I am using push_back to add Lasers to my vector elsewhere in the code.
std::vector<Laser> m_Lasers;
for (int i = 0; i != m_Lasers.size(); i++)
{
m_Lasers[i].ClearLaser();
if (m_Lasers[i].GetX() > m_ScreenWidth || m_Lasers[i].GetX() < 0 || m_Lasers[i].GetY() < 0)
{
//erase the vector
m_Lasers.erase(m_Lasers.begin() + i);
i--;
}
}
my =operator is defined as:
void operator=(const Laser& L){};
in my laser class. I think my issue may be with this.
Thank you so much for you help!