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也可以綁定類的成員,用法同綁定成員函數,加&;