问题
在编译时报std::bind未找到匹配的重载函数
std::bind(&A::print, this, num);
原因
bind到类的成员函数时,成员函数有重载
class A
{
public:
void print(int num)
{
std::cout << "num = " << num << std::endl;
}
void print(const std::string& str)
{
std::cout << "str = " << str << std::endl;
}
};
解决
需要显示指定函数绑定类型
using mf_printnum = void(A::*)(int);
using mf_printstr = void(A::*)(const std::string&);
std::bind((mf_printnum )&A::print, this, num);