64,701
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
using namespace std;
class test
{
public :
int fun(int param,int param2) { return param+param2; }
};
int main()
{
vector<test*> vt;
vt.push_back(new test);
vt.push_back(new test);
vt.push_back(new test);
vt.push_back(new test);
for_each(vt.begin(), vt.end(), bind2nd(mem_fun1(&test::fun), 100,100));
return 0;
}
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
using namespace std;
class test
{
public :
int fun(int param) { cout<<param<<endl; return 0; }
};
int main()
{
vector<test*> vt;
vt.push_back(new test);
vt.push_back(new test);
vt.push_back(new test);
vt.push_back(new test);
for_each(vt.begin(), vt.end(), bind2nd(mem_fun1(&test::fun), 100));
return 0;
}
void main(){
int i;
vector <CShape*> v;
v.push_back(new CShape);
v.push_back(new CRect);
v.push_back(new CCircle);
for_each(v.begin(),v.end(),mem_fun(&CShape::Disp));
for(i=0;i <3;i++){
delete v[i];
// v.pop_back() ; 这里不能这么做
}
v.clear(); // 在这里再清空
}