The code snippet is as follows:
...
void TestFunc(int& data)
{
...
}
int data = 0;
std::thread oneThread(testFunc, data); // 方式1 error
std::thread oneThread(TestFunc, std::ref(data)); // 方式2 ok
...
When configured std::thread
when reference object needs to be passed, directly using Embodiment 1 will compile error , it should be used Embodiment 2 through std::ref()
the package to achieve the purpose of transmitting reference.