Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

PREVIOUS NEXT
Code Example
Cpp :: how to use mersenne_twister_engine in c++ to generate random numbers 
Cpp :: c++ x y in arrau 1d 
Cpp :: multi variable assignment cpp 
Cpp :: how to type cast quotient of two integers to double with c++ 
Cpp :: nothrow new in cpp 
Cpp :: Create an algorithm to identify what is the next largest element on a stack (using stack/queue operations only) INPUT: [ 10, 3, 1, 14, 15, 5 ] OUTPUT: 10 - 14 3 - 14 1 - 14 14 - 15 15 - -1 5 - -1 
Cpp :: convert into acsii c++ 
Cpp :: cpp pointer to two dimensional array 
Cpp :: last index of array c++ 
Cpp :: Write a CPP program to calculate sum of first N natural numbers 
Cpp :: C++ initializing a thread with a public function of a class 
Cpp :: map::begin 
Cpp :: c++ multiple if conditions 
Cpp :: Data Encapsulation in C++ 
Cpp :: how to find the sum of elements in a stack in cpp 
Cpp :: c++ cout update percentage 
Cpp :: crtdbg c++ 
Cpp :: c++ string to const char* 
Cpp :: linked 
Cpp :: C++ Function-style Casting 
Cpp :: how to know how many numbers i deleted with erase command on multiset c++ 
Cpp :: store binary data in buffer 
Cpp :: c++ void to avoid functions 
Cpp :: ue4 foreach loop c++ 
Cpp :: for in c++ example 
Cpp :: windows install cppcheck 
Cpp :: Code Example of Switch Statement in C++/Java 
Cpp :: C++ Things to Remember 
Cpp :: multiply two arbitrary integers a and b (a greater than b) 
Cpp :: online compiler cpp 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =