无法访问多映射迭代器的方法
Unable to access methods of multimap iterator?
我不知道出了什么问题,但我无法访问我的迭代器所指的对象的方法。这是我所拥有的:
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;
相关文章:
- 使用迭代器替换映射中的常量项的方法
- 创建可以遍历 std::map 值的通用模板迭代器的最简单方法是什么?
- 从基于迭代器的for循环转换后,如何在map::find()中调用方法
- 在 C++17 中实现迭代器和const_iterator的正确方法是什么?
- 编译错误 std::vector<std::shared_ptr<T>>迭代器和擦除方法
- 如何使用 SFINAE 从 end() 方法返回 (const_) 迭代器
- 如何使用迭代器作为参数方法?
- 迭代器方法无法从Const_iterator继承
- 是否有一种方法可以使用Boost Serialization序列化迭代器
- 有关使用矢量迭代器访问对象方法的问题
- 如何从内联模板方法返回通用矢量迭代器
- 初始化迭代器的最佳方法是什么?
- 无法将迭代器传递给 C++ 中的类方法
- 返回迭代器内容并将其递增的简单方法
- 实现迭代器通用方法的正确方式
- 迭代器回到递归方法的开头
- 使用矢量迭代器访问方法
- C++迭代器作为类方法中使用的类成员
- C++ 迭代器与对象与 length() 方法
- 可能STL迭代器方法引发异常