在地图值上制作自定义迭代器时出现 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; }

有什么问题?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)