Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- size_t i = 0;
- while (i < m_actors.size())
- {
- if (m_actors[i]->is_active() == false)
- {
- // First delete the actor being pointed to by m_actors[i]
- delete m_actors[i];
- // Then we erase the pointer m_actors[i] from the m_actors vector
- // Erase needs an iterator to be given as its parameter to know which element in the vector to erase
- // So we will define our iterator and set it equal to m_actors.begin() and add the element number it is in the vector
- auto itr = m_actors.begin() + i;
- // Notably the erase function actually shrinks the vector and moves all the other elements over
- // So we do not need to increase i here
- m_actors.erase(itr);
- }
- else
- i++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement