I get different results iterating through the same vector using two different methods. Why?
When I iterate through a vector using what I understand to be the preferred method I get back junk. If use a different method it works fine. Why am I getting inconsistent results depending on the method I choose?
for(vector <NgramOutput*>::iterator sausage = (*sausageCarton)->getSausageBox().begin(); sausage != (*sausageCarton)->getSausageBox().end(); ++sausage){
dosomething(*sausage);
}
for (int i=0; i < sausage.size(); i++) {
dosomething(sausage[i]);
}
As far as I know both should do basically the same thing (although there may be differences in speed?) but for me the first one produces junk such as invalid or null pointers scattered throughout. The second method gives the expected results.