boost :: thread变量的前向声明

Shw*_*eta 5 c++ boost

有人可以请告诉我,我们可以转发声明一个boost :: thread变量.boost :: thread t(thread); 启动一个线程,但我想在某个地方声明它并在其他地方启动它.Thanx提前.

我用的时候

boost::thread t;
t=boost::thread (thread);

/usr/include/boost/noncopyable.hpp: In copy constructor ‘boost::thread::thread(const boost::thread&)’:
/usr/include/boost/noncopyable.hpp:27: error: ‘boost::noncopyable_::noncopyable::noncopyable(const boost::noncopyable_::noncopyable&)’ is private
/usr/include/boost/thread/thread.hpp:35: error: within this context
thr.cpp: In function ‘int main()’:
thr.cpp:20: note: synthesized method ‘boost::thread::thread(const boost::thread&)’ first required here 
/usr/include/boost/noncopyable.hpp: In member function ‘boost::thread& boost::thread::operator=(const boost::thread&)’:
/usr/include/boost/noncopyable.hpp:28: error: ‘const boost::noncopyable_::noncopyable& boost::noncopyable_::noncopyable::operator=(const boost::noncopyable_::noncopyable&)’ is private
/usr/include/boost/thread/thread.hpp:35: error: within this context
thr.cpp: In function ‘int main()’:
thr.cpp:20: note: synthesized method ‘boost::thread& boost::thread::operator=(const boost::thread&)’ first required here 
Run Code Online (Sandbox Code Playgroud)

Fré*_*idi 4

据我所知,唯一的方法是使用threadmove 语义

boost::thread t;  // Will be initialized to `Not-a-Thread`.

// Later...
t = boost::thread(your_callable);
// Now `your_callable()` runs inside a new thread that has been moved to `t`.
Run Code Online (Sandbox Code Playgroud)

编辑:从您发布的错误消息来看,您似乎无法在您的 boost 版本中使用移动语义。如果是这种情况,恐怕您将无法初始化thread实例并稍后启动它。