no matching constructor for initialization of 'std::thread'

自古美人都是妖i 提交于 2019-12-01 14:38:41

You need to instantiate your function:

thread_vector.push_back(std::thread(thread_do<In, Out>,     // you need to instantiate your template function 
                                    std::ref(input_queue),  // pass parameters by ref 
                                    std::ref(process),      // - // -
                                    std::ref(output_vector))// - // -
                                    );

This minimal, complete example (hint) shows you how to call a template member function in another thread.

#include <thread>

struct X
{

  template<class A, class B> void run(A a, B b)
  {
  }

  template<class A, class B>
  void run_with(A a, B b)
  {
    mythread = std::thread(&X::run<A, B>, this, a, b);
  }

  std::thread mythread;
};

int main()
{
  X x;
  x.run_with(10, 12);
  x.mythread.join();
}

Note that std::thread's constructor is not able to auto-deduce template arguments. You have to be explicit.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!