Answers for "passing reference to thread c++"

0

passing reference to thread c++

void foo(int& b)
{
    b = 10;
}

int a = 1;
std::thread thread{ foo, std::ref(a) }; //'a' is now really passed as reference

thread.join();
std::cout << a << '\n'; //Outputs 10
Posted by: Guest on June-07-2021

Browse Popular Code Answers by Language