0
我被要求用與istream_iterator相同的函數編寫迭代器,迭代器的名稱是CMyistream_iterator。我想設置*運算符的函數,因爲它在迭代器中使用。模板和運算符重載和迭代器
template<class T>
class CMyistream_iterator{
public:
T my;
T* cm;
CMyistream_iterator(istream& x):my(x){};
T operator * (CMyistream_iterator<T>& p);
};
template<class T>
T CMyistream_iterator<T>::operator * (CMyistream_iterator<T>& p){return p.my;}
int main()
{
CMyistream_iterator<int> inputInt(cin);
int n1,n2,n3;
n1 = * inputInt;
}
但代碼出錯了,並說「不匹配'operator *'(操作數類型是CMyistream)」。任何人都可以幫我嗎?