Storing an `std::thread` object as a class member
I'm trying to keep an std::thread object inside a class.
class GenericWindow
{
public:
void Create()
{
// ...
MessageLoopThread = std::thread(&GenericWindow::MessageLoop,
*this);
}
private:
std::thread MessageLoopThread;
void GenericWindow::Destroy() // Called from the destructor
{
SendMessageW(m_hWnd, WM_DESTROY, NULL, NULL);
UnregisterClassW(m_ClassName.c_str(), m_WindowClass.hInstance);
MessageLoopThread.join();
}
void GenericWindow::MessageLoop()
{
MSG Msg;
while (GetMessageW(&Msg, NULL, 0, 0))
{
if (!IsDialogMessageW(m_hWnd, &Msg))
{
TranslateMessage(&Msg);
DispatchMessageW(&Msg);
}
}
}
}; // LINE 66
Error given:
[Line 66] Error C2248: 'std::thread::thread' : cannot access private
member declared in class 'std::thread'
This error message doesn't help me, I'm not trying to access any private
member of the 'std::thread' class.
What is wrong in my code? How do I fix it?
No comments:
Post a Comment