#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
class Myprint : public binary_function<int, int, void> {
public:
void operator() (int v1, int v2) const {
cout << "v1 = " << v1 << " v2 = " << v2 << endl;
cout << v1 + v2 << endl;
}
};
void FunMyPrint(int val) {
cout << val << endl;
}
void test01() {
Myprint print;
vector<int> vv;
for (int i = 0; i < 10; i++) {
vv.push_back(i);
}
int num = 200;
for_each(vv.begin(), vv.end(), bind2nd(print, num));
//绑定适配器,将一个二元函数对象转变成一元函数对象
//仿函数适配器 bind1st bind2nd 绑定适配器
}
int main() {
test01();
getchar();
return 0;
}
仿函数适配器 bind1st bind2nd
最新推荐文章于 2024-08-30 18:40:43 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)