Currently trying to pass an object by reference to another thread but I get errors when I try to build my solution.
void OrderServer(Orders& customerOrders)
{
Item tempItem;
customerOrders.add(tempItem);
}
int main()
{
Orders customerOrders();
auto serverThread = std::thread(OrderServer, std::cref(customerOrders));
serverThread.detach();
return 0;
}
The following is the error:
c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.11.25503\include\thr\xthread(240): error C2672: 'std::invoke': no matching overloaded function found 1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.11.25503\include\thr\xthread(248): note: see reference to function template instantiation 'void std::_LaunchPad<_Target>::_Execute<0,1>(std::tuple> &,std::integer_sequence<_Ty,0,1>)' being compiled
std::crefto a non-constant parameter function. Try passingstd::ref()or making your function accept aconstparameter reference. - Galikstd::cref. - StoryTeller - Unslander Monica