这是我的代码:

template <class a, class b>
class LinkedListIter{

    public:
        LinkedListIter(b* iterable){

            this->iterable = iterable;
            this->head = this->iterable->head;
            this->curr = this->iterable->curr;
            this->iter_pos = 0;

        };
        void operator++(int dummy){

            this->iter_pos++;

        };
        friend std::ostream& operator<< (std::ostream& o, LinkedListIter const& lli);

    private:
        a* head;
        a* curr;
        b* iterable;
        int iter_pos; //The current position if the iterator

    };

std::ostream& operator<< (std::ostream& o, LinkedListIter const& lli){
    return o << lli.get(lli.iter_pos);
}

我在声明std::ostream& operator<< (std::ostream& o, LinkedListIter const& lli)的那一行上收到一条错误消息,说LinkedListIter没有命名类型。为什么会这样呢?

最佳答案

LinkedListIter是一个类模板,而不是一个类。因此,您的运算符(operator)也需要成为模板。

template<typename a, typename b>
std::ostream& operator<< (std::ostream& o, LinkedListIter<a,b> const & lli){
...

08-06 14:22