I have a function:
void reader (std::istream *in, std::string& out)
{
(*in) >> out;
}
I can easily call it with either:
reader(&std::cin, out);
or
std::function<void(std::istream*, std::string&)> r = reader;
r(&std::cin, out);
However, as soon as i attempt to create the thread from this function with either:
std::thread *reader = new std::thread(reader, &std::cin, out);
or
std::thread *reader = new std::thread(r, &std::cin, out);
I get some weird errors along the lines of:
/usr/include/c++/4.8/functional: In instantiation of ‘struct std::_Bind_simple<std::function<void(std::basic_istream<char>*, std::basic_string<char>&)>(std::basic_istream<char>*, std::basic_string<char>)>’: /usr/include/c++/4.8/thread:137:47: required from ‘std::thread::thread(_Callable&&, _Args&& ...) [with
_Callable = std::function<void(std::basic_istream<char>*, std::basic_string<char>&)>&; _Args = {std::basic_istream<char, std::char_traits<char> >*&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&}]’ asyncinput.cpp:39:56: required from here /usr/include/c++/4.8/functional:1697:61: error: no type named ‘type’ in ‘class std::result_of<std::function<void(std::basic_istream<char>*, std::basic_string<char>&)>(std::basic_istream<char>*, std::basic_string<char>)>’
typedef typename result_of<_Callable(_Args...)>::type result_type;
^ /usr/include/c++/4.8/functional:1727:9: error: no type named ‘type’ in ‘class std::result_of<std::function<void(std::basic_istream<char>*, std::basic_string<char>&)>(std::basic_istream<char>*, std::basic_string<char>)>’
_M_invoke(_Index_tuple<_Indices...>)
I have attempted to turn the function into a lambda, but that didn't help. I don't know what i'm doing wrong.