#include #include using namespace std; void f1(double& ret) { ret=5.; } int main() { double ret=0.; thread t1(f1, ret);
Jonathan's answer is definitive. Time spent studying it would be time well spent.
In the meantime, modifying the code thus will do what you want - namely send a reference into the thread function:
thread t1(f1, std::ref(ret));