用新的线程& 删除工作正常吗?用于C++ 11的线程,用新的
Q1。试图通过使用新的新线程是正常的?
Q2,加入后有没有问题删除?
例如
class Myclass {
private:
thread *th;
public:
~Myclass(){delete th;};
void create_thread();
void thread_func();
};
Myclass::create_thread()
{
th = new thread(thread_func, this);
th->join();
}
Myclass::thread_func()
{
while(1){};
}
显示的类[违反三规则](http://stackoverflow.com/questions/4172722/what-is-the-rule-of-ree)。使用'new'在动态作用域中构建'std :: thread'没有问题,如果它正确完成的话,但这不是正确的方法。花一些时间了解智能指针。 –
你是什么意思*好吧*?是的,你可以做到。不,你可能不应该这样做... –
@SamVarshavchik *没有错* – Yakk