Pass parameters to std::thread wrapper

后端 未结 4 1427
一个人的身影
一个人的身影 2021-02-09 09:26

I want to implement a small thread wrapper that provides the information if a thread is still active, or if the thread has finished its work. For this I need to pass the functio

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-09 10:04

    In the error message, you can see the difference void (*)() vs void (&)(). That's because std::thread's constructor parameters are std::decayed.

    Add also std::ref to f:

    template< class Function, class... Args>
       ManagedThread::ManagedThread( Function&& f, Args&&... args):
          mActive( false),
          mThread( threadFunction< Function, Args...>, std::ref(mActive), std::ref(f), std::forward(args)...)
    {
    }
    

提交回复
热议问题