I declared an iterator in my header file and after I push back a state inside the vector I reset the iterator like this:
Why do you declare an iterator in a header? Is it global?
Iterators are objects of extremely local scope. In most cases, it's an error to store them -- they're used for iteration, and they become invalid as the underlying container changes.
for (it = states.begin(); it != states.end(); ++it)
{
(*it)->update(window, dt);
}
Don't do that! Declare the iterator locally, that is, inside the for loop.
Or use range-based for loops directly.
If I declare it locally (inside that method only) I get a
vector iterator not incrementable error. The same goes for the range-based for loop.
I could get this to work without using an iterator like this:
for (unsigned int i = 0; i < states.size(); i++)
{
states[i]->update(window, dt);
}
Or with the iterator, but it must be declared in the header file or in the cpp file outside of the methods because I have to
reset it after I clear the vector and push_back another state:
states.push_back(std::move(state));
it = states.begin();