while (this->_data->window.isOpen()) // Main Loop
{
this->_data->machine.ProcessStateChanges();
std::thread t1 (this->_data->machine.ProcessStateChanges);
std::thread t2 (dt = _clock.restart().asSeconds());
std::thread t3 (this->_data->machine.GetActiveState()->HandleInput);
t1.join();
t2.join();
t3.join();
this->_data->display.WindowEvent(this->_data->window);
this->_data->machine.GetActiveState()->Update(dt);
this->_data->machine.GetActiveState()->Draw(dt);
I get an error on std::thread t1 (this->_data->machine.ProcessStateChanges);
and std::thread t3 (this->_data->machine.GetActiveState()->HandleInput);
-- error C3867: 'StateMachine::ProcessStateChanges': non-standard syntax; use '&' to create a pointer to member
And one for HandleInput. Normally this error just tells me that I forgot to put ()
on my functions, I know. But everything i've read on thread tells me that I skip it when taking the arguments for the thread. I've tried both ways.
These two functions are from a shared pointer to a struct called _data, which houses an object (my finite state machine) called machine. ProcessStateChanges checks to see if _data has made any requests to change the stack. Get active state is a function that returns a unique_ptr to the state in a stack on top. and HandleInput is a function in the state. None of these functions take arguments.
Now, when I run it without thread, it runs fine. I'd like it to run the functions concurrently, mostly to play with the thread concept, and trying to squeeze out a little more efficiency. However, I get an error when I try to pass the functions to a thread. I've tried with and without ()
attached.
I tried writing it like in the question page start thread with member function : std::thread t1(&StateMachine::ProcessStateChanges, this->_data);
And unless I'm missing something here, it doesn't work either. I get a huge page of errors starting with error C2672: 'std::invoke': no matching overloaded function found
So my question is, what exactly am I passing as an argument when I create a thread if it's not just a function call? and what would the syntax be for something as complicated as a function call that comes from a Shared Pointer to a Struct object containing a Class object with a function that I want to call? or Even more complicated: a Shared pointer to a struct that has a class object that has a function that returns a reference to a unique pointer to a class object that has a function that I want to call?