generate_n generate使用的问题,

#include
#include
#include
#include
using namespace std;
class IntSequence
{
private:
int value;
public:
IntSequence(int initialValue):value(initialValue){cout<<"a new object!"< int operator()(){return ++value;}
};
int main()
{
listcoll;
generate_n(back_inserter(coll),9,IntSequence(1));
copy(coll.begin(),coll.end(),ostream_iterator(cout," "));cout<<endl;

generate(++coll.begin(),--coll.end(),IntSequence(42));
copy(coll.begin(),coll.end(),ostream_iterator<int>(cout," "));cout<<endl;
while(1);

}

为什么最后输出的只有一个"a new object!"
我的理解是输出9次,每次循环产生一个IntSequence(1)的临时变量。
而实际产生了一个对象,求解为什么。

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^