More answers: C++ Thread taking reference argument failed compile
I'm creating a callable variable to which I'm assigning a lambda-function with arguments:
auto func = [](int &d) -> void { d++; }; How can I use this variable as a std::thread-function passing my argument?
I tried the obvious:
int i; auto t1 = std::thread(func, i); t1.join(); This fails with the compiler telling me that func has no no type named ‘type’ in [..]_Callable(_Args...)>::type result_type;.
EDIT: It is related to the reference of the argument. It works when I pass a pointer (int *i) or a copy (int i).
auto t1 = std::thread(func, std::ref(i));Unrelated, initializei; ub sucks =P