#include <iostream>
#include <thread>
class Ta
{
public:
int &ta_s;
Ta(int taS) : ta_s(taS)
{
std::cout<<"构造函数"<< this <<std::endl;
}
virtual ~Ta()
{
std::cout<<"析构函数"<< this << std::endl;
}
Ta(const Ta &ta):ta_s(ta.ta_s)
{
std::cout<<"拷贝构函数"<< this << std::endl;
}
void operator()()
{
std::cout<<"haha"<< this <<std::endl;
}
};
int main()
{
int a = 0;
Ta ta(a);
std::thread th(ta);
// th.detach();
th.join();
return 0;
}
结果如下所示:
构造函数0x7ffeebff2578
拷贝构造函数0x7ffeebff24e0
拷贝构造函数0x7fd524400648
析构函数0x7ffeebff24e0
haha0x7fd524400648
析构函数0x7fd524400648
析构函数0x7ffeebff2578
请问,拷贝构造调用了两次吗?我已知晓的就一次,请赐教!