1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| #include<iostream> #include<functional> using namespace std; using namespace std::placeholders;
template <typename R1 , typename R2> struct Calc { void add(R1 a) { cout << a << endl; }; void add_1(R1 a, R1 b) { cout << a + b << endl; } };
int main(int argc, char * args[]) {
//函数指针 void(Calc<int, double>::*fc)(int a) = &Calc<int, double >::add; // fc(25); //显然上面的式子比较的麻烦 Calc < int, int> calc; auto fun = bind(&Calc<int, int >::add, &calc, _1); auto fun_2 = bind(&Calc<int, int >::add_1, &calc, _1,_2); fun(123); fun_2(12,24); cin.get(); return 0; }
|