【发布时间】:2019-12-01 14:18:28
【问题描述】:
为什么我不能从析构函数中调用我的线程向量?使用析构函数有什么规则吗?
void p ()
{
std::cout << "thread running " << std::endl;
}
class VecThreads // Error: In instantiation of member function 'std::__1::vector<std::__1::thread, std::__1::allocator<std::__1::thread> >::vector' requested here
{
public:
std::vector<std::thread> threads;
VecThreads() {
threads.push_back(std::thread(p));
}
~VecThreads()
{
threads[0].join();
}
};
int main(int argc, const char * argv[]) {
VecThreads h = VecThreads();
//h.threads[0].join(); // delete deconstructor and use this works fine
return 0;
}
我得到的错误:
调用类'std::__1::thread'的私有构造函数
【问题讨论】:
标签: c++ vector copy-constructor stdthread move-constructor