#include#include using namespace std; //方式一:类使用bind struct Foo{ void print_sum(int n1, int n2, int n3){ cout << "sum = " << n1 + n2 + n3 << endl; } }; //方式二:函数使用bind void print(int &n1, int &n2, int &n3){ n1++; n2++; n3++; } int main(){ //方式一:类实现 Foo foo; auto callback = std::bind(&Foo::print_sum, &foo, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); callback(5, 10, 15);//回调函数 //std::placeholders::_1...相当于占位符 //方式二 int a = 1, b = 2, c = 3; auto func2 = std::bind(print, a, b, std::ref(c)); //引用传参 func2(); cout <<"a = " << a << endl; cout <<"b = " << b << endl; cout <<"c = " << c << endl; }



