Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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 << '
'; //Outputs 10
Source by riptutorial.com #
 
PREVIOUS NEXT
Tagged: #passing #reference #thread
ADD COMMENT
Topic
Name
8+4 =