我有一个vector<int>
叫pitches
. 我在bad access
下面的最后一行定期:
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
我之前曾尝试过*pitches.begin()
最后一行,但总是提供错误的访问权限,我现在明白了。但是,虽然我现在很少得到它,但play=*(pitches.begin());
偶尔还是会这样做。我在上面看不到任何会导致这种情况的东西,任何建议表示赞赏。