Answer the question
In order to leave comments, you need to log in
How to pass a function object by reference to a stream function argument?
There are two functions: void handler1(std::string& s) {}
and
void thread1(std::function<void(std::string&)>& f) {}
auto f = std::bind(handler1, _1);
std::thread t(&thread1, std::ref(f)); //<-- Ошибка :(
Answer the question
In order to leave comments, you need to log in
The thread function takes a reference to some class. You are trying to stick a reference to a completely different class. The mistake is quite logical. Try giving the type you expect:
std::function<void(std::string&)> f = std::bind(handler1, _1);
//или тупо
std::function<void(std::string&)> f = handler1;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question