from:http://blog.csdn.net/mrknight/article/details/9418469
I just happened to have met myself. This error. Actually, it's very low-level.
Recently using C + +, the map container was used in the program, prompting for error Map/set iterator not dereferencable.
At first it was doubtful that the iterator had not lifted the reference ...
The final discovery is that the element indicated by the iterator is empty (that is, end), but the program has a bug in the loop that uses the iterator, which causes an empty iterator to be used because the existing condition is sufficiently constrained.
Map<string, pair<double, double>>::iterator it = Shotlist.find
(shotid);
while (It->first.find (String ("shot") + ID)!= string::npos)
{
if It->second.first <= start && It->second.second >= start| |
It->second.first <= End && it->second.second >= end)
{
Shotresultlist.push_back (it-> a);
++it;
}
After modification
Map<string, pair<double, double>>::iterator it = Shotlist.find
(shotid);
while (it!= shotlist.end () &&
it->first.find (String ("shot") + ID)!= string::npos)
{
if (it- >second.first <= start && it->second.second >= start| |
It->second.first <= End && it->second.second >= end)
{
Shotresultlist.push_back (it-> a);
++it;
}
You can see that the error code does not cause an error because it!= shotlist.end () condition constraints.