C++ std::thread “Attempt to use a deleted function”

后端 未结 1 1849
小鲜肉
小鲜肉 2021-01-20 01:49

Here\'s the relevant code and the relevant error, I\'m not really sure what to make of it.

Breaker::Thread::Thread(std::string name, std::string desc, void*          


        
相关标签:
1条回答
  • 2021-01-20 02:04

    I think the problem is the declaration of the parameter func. It is declared as a void pointer instead of a pointer to a function returning void.

    Instead of,

    Breaker::Thread::Thread(std::string name, std::string desc, void* func)
    

    I think you mean,

    Breaker::Thread::Thread(std::string name, std::string desc, void (*func) ())
    

    Note, loop must be a static member for this to work.

    Additionally, you might want to consider using std::function. It's a much more modern and cleaner interface than using void pointers.

    Breaker::Thread::Thread(std::string name, std::string desc, std::function<void()> func)
    
    0 讨论(0)
提交回复
热议问题