Say I have a class:
class This
{
void that(int a, int b);
};
and in my main function I need to start 'that' in a thread, and pass it 2 arguments. This is what I have:
void main()
{
This t;
t.that(1,2); //works unthreaded.
std::thread test(t.that(1,2)); // Does not compile. 'evaluates to a function taking 0 arguments'
std::thread test2(&This::that, std::ref(t), 1, 2); //runs, but crashes with a Debug error.
}
I have searched, but have only found how to pass arguments to a thread, and to run a function from another class in a thread, but not both!
What is the correct way to do this?