I have a vector<int>
called pitches
. I'm getting periodic bad access
on the last line below:
int play = 0;
bool didFind = 0;
vector<int>::const_iterator iterator;
for (iterator = pitches.begin(); iterator != pitches.end(); ++iterator) {
if (*iterator > lastpitch) { // lastpitch is an int
didFind = 1;
play = *iterator;
break;
}
}
if (!didFind) play = *(pitches.begin()); // this line gives me bad access
I had previously tried *pitches.begin()
on the last line but that always provided bad access and I understand that now. But while I get it less often now, this play=*(pitches.begin());
is still doing the same occasionally. I cannot see anything in the above that would cause that, any suggestions appreciated.