Il mio obiettivo è mantenere un oggetto std::thread
come membro dati e inizializzarlo quando necessario.
Non riesco a farlo (come nel mio codice di seguito) perché il costruttore di copie della classe std::thread
viene cancellato. c'è un altro modo per farlo?È possibile definire uno std :: thread e inizializzarlo in seguito?
class MyClass
{
public:
MyClass():DiskJobThread(){};
~MyClass();
void DoDiskJobThread();
private:
int CopyThread(const std::wstring & Source, const std::wstring & Target);
int MoveThread(const std::wstring & Source, const std::wstring & Target);
std::thread DiskJobThread;
};
MyClass::~MyClass()
{
DiskJobThread.join();
}
void MyClass::DoDiskJobThread()
{
std::wstring Source = GetSource();
std::wstring Target = GetTarget();
int m_OperationType = GetOperationType();
if (m_OperationType == OPERATION_COPY)
{
DiskJobThread = std::thread(&MyClass::CopyThread, *this, Source, Target);
}
else if (m_OperationType == OPERATION_MOVE)
{
DiskJobThread = std::thread(&MyClass::MoveThread, *this, Source, Target);
}
}
Passare 'questo' al posto del dereferenziamento' * questo'. –