我不知道为什么我会收到此错误:
src/Cronologia.cpp: In member function ‘void Cronologia::recuento()’:
src/Cronologia.cpp:106:9: error: expected primary-expression before ‘int’
map<int,EventoHistorico> ::const_iterator itm;
^
src/Cronologia.cpp:106:9: error: expected ‘;’ before ‘int’
所以我的迭代器没有被声明,我得到更多没有声明的错误。
这是我的代码:
void Cronologia::recuento()
{
int map = cronologias.size();
cout << "Numero de anios: " << map << endl;
map<int,EventoHistorico> ::const_iterator itm;
for(itm=cronologias.begin();itm!=cronologias.end();++itm)
{
cout << "Anio: " << (*itm).first;
cout << "Numero de eventos: " << (*itm).second.size() << endl;
}
}
它很奇怪,因为Im在其他函数中声明了相同的东西,并且没有错误:
Cronologia Cronologia::filtrarIntervalo(int inf, int sup)
{
Cronologia result;
map<int,EventoHistorico>::const_iterator itinf, itsup;
itinf = cronologias.find(inf);
itsup = cronologias.find(sup);
}