c++ - 对地图值进行自定义迭代器时出现 C++ 错误
问题描述
我有这个代码:
template <typename Iter>
class map_iterator : public std::iterator<std::bidirectional_iterator_tag, typename Iter::value_type::second_type> {
public:
map_iterator() {}
map_iterator(Iter j) : i(j) {}
map_iterator& operator++() { ++i; return *this; }
map_iterator operator++(int) { auto tmp = *this; ++(*this); return tmp; }
map_iterator& operator--() { --i; return *this; }
map_iterator operator--(int) { auto tmp = *this; --(*this); return tmp; }
bool operator==(map_iterator j) const { return i == j.i; }
bool operator!=(map_iterator j) const { return !(*this == j); }
reference operator*() { return i->second; }
pointer operator->() { return &i->second; }
protected:
Iter i;
};
template <typename Iter>
inline map_iterator<Iter> make_map_iterator(Iter j) { return map_iterator<Iter>(j); }
using route_departure_container = std::map<packed_time, route_departure_o>;
template <typename Iter>
using route_departure_const_iterator = map_iterator;
template <typename Iter>
route_departure_const_iterator<Iter> departure_at(const std::pair<key, const platform_route_o&>& pr, packed_time tm);
我收到编译器错误:语法错误:缺少';' 在 '*' 等之前和 C4430 缺少行上的类型说明符
reference operator*() { return i->second; }
pointer operator->() { return &i->second; }
问题是什么?
解决方案
推荐阅读
- java - boolean isStepCountPresent = (flag & 0x01) != 0 在java中是什么意思?
- c++ - 类构造函数中 pthread_t 的生命周期
- python - 为什么我会收到“CommandError:App 'app_name' 没有迁移。” 使用 Heroku 时?
- python - 如何在我的主窗口中使用另一个窗口的输入(使用 PyQt5 和 qt-designer)?
- java - 使用 Spring 数据 JPA 规范进行组合时如何使用连接
- r - 强制向日葵图从 x=0 开始
- javascript - 使用 DOM 创建嵌套元素
- sql - 如何使用 sql 查询作为字符串参数?
- python - 是否可以使用 tf.keras.models.clone_model 来改变数据输入的形状?
- java - 通过异常 VS 传播错误对象中断反应式管道