class CP
{
public:
int print(int a, int b)
{
printf("CP print() a=%d, b=%d");
}
};
int print(int a, int b)
{
printf("print() a=%d, b=%d");
}
CP f &rf=f;
CP* pf;
bind(print, _1, _2)(10, 20); //ok
bind(&print, _1, _2)(10, 20); //ok
bind(CP::print, f, _1, _2)(10, 20); //error
bind(&CP::print, f, _1, _2)(10, 20); //ok
bind(&CP::print, rf, _1, _2)(10, 20); //ok
bind(&CP::print, pf, _1, _2)(10, 20); //ok
error原因:
CP::print必需要& 表明这是一个成员函数指针
bind也可以绑定类的成员,用法同绑定成员函数,加&;