64,691
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <list>
#include <algorithm>
#include <functional>
using namespace std;
class AddValue
{
public:
AddValue(int v) : theValue(v) {}
void operator() (int& elem) const
{
elem += theValue;
}
private:
int theValue;
};
int main()
{
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
list<int> ilst(a, a+sizeof(a)/sizeof(a[0]));
for_each (ilst.begin(), ilst.end(), AddValue(10));
for (list<int>::iterator iter = ilst.begin(); iter != ilst.end(); iter++)
cout << *iter << " ";
return 0;
}