// Description: STL encountered in the use of
//Create Date: 2019-07-08 09:19:15
//Author: channy
Notes_STL_List_And_Map
Given: After erase the iterator will expire, should reset the iterator
Problem: the program will still crash
Cause: This code is unknown reasons. Work appeared erase code is a local variable, in fact, did not erase map
Follow-up: a good try after a few days. . .
(Did not experience the bug interpreted as theology is not a good programmer programmers)
Code:
#include <QCoreApplication>
#include <QDebug>
int main(int argc, char *argv[])
{
//QCoreApplication a(argc, argv);
QList<int> ql;
qDebug() << ql.size();
QMap<int, QList<int>> qm;
qm[0] = ql;
for (QMap<int, QList<int>>::iterator iter = qm.begin(); iter != 大专栏 Notes_STL_List_And_Map"n">qm.end(); iter++) {
qDebug() << qm.size();
for (QList<int>::iterator itr = iter->begin(); itr != iter->end(); itr++) {
itr = iter->erase(itr);
}
if (iter->size() == 0) {
iter = qm.erase(iter);
//如果不加下面的判断,会崩溃。。。iter != qm.end() == true. But why???
if (qm.size() == 0) break;
}
}
//return a.exec();
return 0;
}