in this class we have a std::thread that runs in the constructor and has access to the _id
of this class. how can we implement copy and move constructor and assignment for this class?
class MyClass
{
public:
explicit MyClass(int id):
_id {id} {
std::cout << "constrn";
_thread = std::thread([this](){
while(true)
std::cout << "id:" << _id << std::endl;
});
}
~MyClass() {
if(_thread.joinable()) _thread.join();
}
private :
int _id;
std::thread _thread;
};