多线程对象生命期提问
我是刚入行的小白,真心求教:
问题描述:
class Father
{
Father(){ /*构造函数*/ };
~Father(){ /*析构函数*/ };
print(/*打印*/);
};;
void thread_work(Father& a)
{
a.print(); //####提问:这里为什么会调用析构?
}
int main()
{
std::thread th(thread_work);
th.join();
}
补充:改为 void thread_work(Father* a); 就可以了,
原型是客户端发数据,因为调用析构,所以服务端接收到2个网络指令了,拜托大神解疑啦,感谢感谢!
还有 能不能说下这属于哪方面知识呢?