这个generate算法跑完为啥是2 4 不是 2 2 呢?
#include<iostream>#include<algorithm>
#include<functional>
#include<iterator>
#include<vector>
using namespace std;
class even{
int x;
public:
even():x(0){}
int operator()(){return x += 2; }
};
int main(){
vector<int>ivector3(2);
fill(ivector3.begin(), ivector3.end(), -1);
ostream_iterator<int>output(cout," ");
copy(ivector3.begin(), ivector3.end(), output);
cout << endl;
generate(ivector3.begin(), ivector3.end(), even()); //
copy(ivector3.begin(), ivector3.end(), output);
cout << endl;
return 0;
}