我有下面的代碼,其中我試圖做一個模板化的安全數組迭代器。部分專精不專門化任何模板參數
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,但我從來沒有使用它,但顯然並非如此。
唉唉!對。這是有道理的,它的工作原理。謝謝。 –