我有以下代码,我试图在其中创建一个模板化的安全数组迭代器。
template <typename T>
class SArrayIterator;
template <typename E>
class SArray;
class SArrayIteratorException;
template <typename T>
class SArrayIterator<T> {//<--line 16
friend std::ostream &operator <<(std::ostream &os, const SArrayIterator<T> &iter);
public:
SArrayIterator<T>(SArray<T> &sArr) : beyondLast(sArr.length()+1), current(0), sArr(sArr){}
T &operator *(){
if (current == beyondLast) throw SArrayIteratorException("Attempt to dereference 'beyondLast' iterator");
return sArr[current];
}
SArrayIterator<T> operator ++(){
if (current == beyondLast) throw SArrayIteratorException("Attempt to increment 'beyondLast' iterator");
current++;
return *this;
}
bool operator ==(const SArrayIterator<T> &other) {return sArr[current] == other.sArr[current];}
bool operator !=(const SArrayIterator<T> &other) {return !(*this == other);}
private:
int first, beyondLast, current;
SArray<T> sArr;
};
但是,当我编译时,我得到-
array.h:16: error: partial specialization ‘SArrayIterator<T>’ does not specialize any template arguments
我不确定这意味着什么。我的猜测是它说我声明了一个 T 但我从不使用它,但这显然不是这种情况。