运算符重载的问题,帮忙看一下
一个istream_iterator的模拟程序,想问一下为什么重载++运算符的时候要加int?#include <iostream>
#include <string>
using namespace std;
template <class T>
class CMyistream_iterator
{
public:
T value;
CMyistream_iterator(istream& i){
i>>value;
}
T operator* (void){
return value;
}
void operator ++ (int){
cin>>value;
}
};
int main()
{
int t;
cin >> t;
while( t -- ) {
CMyistream_iterator<int> inputInt(cin);
int n1,n2,n3;
n1 = * inputInt;
int tmp = * inputInt;
cout << tmp << endl;
inputInt ++; //如果上面红色语句不加(int),这一句会报错
n2 = * inputInt;
inputInt ++;
n3 = * inputInt;
cout << n1 << " " << n2<< " " << n3 << " ";
CMyistream_iterator<string> inputStr(cin);
string s1,s2;
s1 = * inputStr;
inputStr ++;
s2 = * inputStr;
cout << s1 << " " << s2 << endl;
}
return 0;
}