I am trying to iterate in reverse through a vector. I've "made" an iterator using a typedef:
typedef std::vector<Object*>::iterator Cursor;
My problem is, this function seems to crash when it reaches the begin of the vector. I have the following code:
void InsertFunc(Cursor& it, Object& o) {
vec_.insert(it, o);
--it;
for (; it >= vec_.begin(); --it) {
if ((*it)->type() == Object::SomeType) {
do_something
} else {
do_something_else
}
}
std::cout << "Insertion succes!" << std::endl;
}
I've tested it already, and I know for sure that the function reaches the begin of the vector, but then the program just terminates and the message "Insertion succes!" is never printed. Any idea why?