C++ C++;标准:螺纹;尝试使用已删除的函数";

C++ C++;标准:螺纹;尝试使用已删除的函数";,c++,linux,multithreading,c++11,C++,Linux,Multithreading,C++11,这是相关的代码和相关的错误,我真的不知道该怎么做 Breaker::Thread::Thread(std::string name, std::string desc, void* func) { std::thread _thread(func); _thread.join(); } 这在thread.cpp中,下一个在log.cpp中 thread = new Breaker::Thread("System Log", loop); 及 以下是相关错误: In file

这是相关的代码和相关的错误,我真的不知道该怎么做

Breaker::Thread::Thread(std::string name, std::string desc, void* func)
{
    std::thread _thread(func);

    _thread.join();
}
这在thread.cpp中,下一个在log.cpp中

thread = new Breaker::Thread("System Log", loop);

以下是相关错误:

In file included from /home/nope/Documents/dev/C++/Breaker Engine/src/core/thread.cpp:25:
In file included from /home/nope/Documents/dev/C++/Breaker Engine/src/core/thread.h:28:
/usr/bin/../include/c++/v1/thread:332:5: error: attempt to use a deleted function
    __invoke(_VSTD::move(_VSTD::get<0>(__t)), _VSTD::move(_VSTD::get<_Indices>(__t))...);
    ^
/usr/bin/../include/c++/v1/thread:342:5: note: in instantiation of function template specialization 'std::__1::__thread_execute<void *>' requested here
    __thread_execute(*__p, _Index());
    ^
/usr/bin/../include/c++/v1/thread:354:42: note: in instantiation of function template specialization 'std::__1::__thread_proxy<std::__1::tuple<void *> >'
      requested here
    int __ec = pthread_create(&__t_, 0, &__thread_proxy<_Gp>, __p.get());
                                         ^
/home/nope/Documents/dev/C++/Breaker Engine/src/core/thread.cpp:95:14: note: in instantiation of function template specialization
      'std::__1::thread::thread<void *&, void>' requested here
        std::thread _thread(func);
                    ^
/usr/bin/../include/c++/v1/type_traits:1027:5: note: '~__nat' has been explicitly marked deleted here
    ~__nat() = delete;
    ^
包含在/home/nope/Documents/dev/C++/Breaker-Engine/src/core/thread.cpp:25中的文件中:
在/home/nope/Documents/dev/C++/Breaker-Engine/src/core/thread.h中包含的文件中:28:
/usr/bin/。/include/c++/v1/thread:332:5:错误:尝试使用已删除的函数
__调用(_-VSTD::move(_-VSTD::get(u-t)),_-VSTD::move(_-VSTD::get(u-t))…);
^
/usr/bin/。/include/c++/v1/thread:342:5:注意:在函数模板专门化的实例化中,此处请求“std::\uu 1::\uu thread\u execute”
__线程执行(*uuu p,_Index());
^
/usr/bin/。/include/c++/v1/thread:354:42:注意:在函数模板专门化的实例化中'std::uu 1::u thread_proxy'
在此请求
int_uuuec=pthread_create(&uuu t_u,0,&uuu thread_proxy,uuu p.get());
^
/home/nope/Documents/dev/C++/Breaker-Engine/src/core/thread.cpp:95:14:注意:在函数模板专门化的实例化中
此处请求了“std::u 1::thread::thread”
标准::线程_线程(func);
^
/usr/bin/。/include/c++/v1/type_traits:1027:5:注意:“~_nat”已在此处明确标记为已删除
~\u nat()=删除;
^

我认为问题在于参数
func
的声明。它被声明为void指针,而不是指向返回void的函数的指针

而不是

Breaker::Thread::Thread(std::string name, std::string desc, void* func)
我想你是说

Breaker::Thread::Thread(std::string name, std::string desc, void (*func) ())
注意,
循环
必须是静态成员才能工作

< St>另外,您可能需要考虑使用STD::Fuff.它比使用空洞指针更为现代和更干净的接口。

Breaker::Thread::Thread(std::string name, std::string desc, std::function<void()> func)
Breaker::Thread::Thread(std::string name,std::string desc,std::function func)
Breaker::Thread::Thread(std::string name, std::string desc, std::function<void()> func)