无法访问多映射迭代器的方法

Unable to access methods of multimap iterator?

本文关键字:迭代器 方法 映射 访问      更新时间:2023-10-16

我不知道出了什么问题,但我无法访问我的迭代器所指的对象的方法。这是我所拥有的:

multimap<long, Note>::iterator notesIT;
notesIT = trackIT->getNoteList().lower_bound(this->curMsr * 1000000);
while(notesIT->first / 1000000 == 1){
    cout << notesIT->first.getStartTime() << endl; // error on this line
    notesIT++;
}

我收到此错误:

error: request for member 'getStartTime' in 'notesIT. std::_Rb_tree_iterator<_Tp>::operator-> [with _Tp = std::pair<const long int, Note>]()->std::pair<const long int, Note>::first', which is of non-class type 'const long int'

也许:

notesIT->second.getStartTime()

编译器告诉你

notesIT->first.getStartTime()

无效,因为您正在尝试在 int 上调用 getStartTime()。 显然,你的意思是在Node上调用它,所以选择迭代器指向的对的第二部分(产生迭代器的Node部分):

cout << notesIT->second.getStartTime() << endl;