Error creating std::thread on Mac OS X with clang: “attempt to use a deleted function”

那年仲夏 提交于 2019-12-05 01:43:35
    _th = std::thread(&Foo::threadFunc, *this);

This tries to make a copy of *this to store in the new thread object, but your type is not copyable because its member _th is not copyable.

You probably want to store a pointer to the object, not a copy of the object:

    _th = std::thread(&Foo::threadFunc, this);

N.B. your program will terminate because you do not join the thread. In your type's destructor you should do something like:

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