I have an existing class with an function
void Foo::startSimulation(std::string system_cmd)
{
//Calling a simulation script from system
//After simulation, there is nothing to do.
//Thread self-terminates.
}
My goal is to make a thread which runs the Foo function.
I have tried std::thread thread1(myFoo.startSimulation(message);
However this returns
: error: no matching constructor for initialization of 'std::thread'
candidate constructor not viable: cannot convert argument of incomplete type 'void' to 'const std::__1::thread'
So my function returns void which the thread can´t run. How can I make the thread exist, and then run the processes the class function would do within that thread.
Is it in any way possible to make the thread.
std::thread thread1; // Creating the thread
thread1.start(myFoo.startSimulation("system cmd");
thread1.detach();
I know the above three lines of code are not working code in c++. std::thread has no .start() function.
However, is there a way to make threads behave in that way?