ITPub博客

首页 > > > c++11 std::bind 如何绑定 一个类的重名函数

c++11 std::bind 如何绑定 一个类的重名函数

作者:choubou 时间:2019-09-19 17:24:26 0 删除 编辑
class Test{
public:
    void work(){
        cout << "in work " << endl;
    }
   
    void work(int x){
        cout << "x = " << x << endl;
    }
};

int main(){

  Test test;
  thread th(std::bind(&Test::work, &test));
  th.join();

  return 0;
}

如上所示,在Test类中,含有两个work函数,函数名相同,但参数不同。我想在main函数中新建一个线程,线程函数为work函数(无参数的那个),请问如何做到?

如果我直接按照上面这样写,会提示找不到确切的函数错误(因为有两个同名的work)。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4548/viewspace-3162575/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-10-08

  • 博文量
    175
  • 访问量
    10708