0
votes

I am having an issue compiling this piece of code error

/usr/include/boost/bind/bind_mf_cc.hpp:91:5: error: initializing argument 5 of ‘boost::_bi::bind_t, typename boost::_bi::list_av_4::type> boost::bind(R (T::*)(B1, B2, B3), A1, A2, A3, A4) [with R = void; T = tcpReader; B1 = const boost::system::error_code&; B2 = unsigned int; B3 = boost::asio::basic_streambuf<>&; A1 = tcpReader*; A2 = boost::system::error_code; A3 = unsigned int; A4 = boost::asio::basic_streambuf<>; typename boost::_bi::list_av_4::type = boost::_bi::list4, boost::_bi::value, boost::_bi::value, boost::_bi::value > >]

void tcpReader::handle_read(const boost::system::error_code& ec, std::size_t bytes_transferred, boost::asio::streambuf& buf)
// inside a class method
boost::asio::streambuf buf;
boost::asio::async_read_until(*sock,buf,"\n" ,
                              boost::bind(&tcpReader::handle_read,this,error,buf.size(),buf)
                              );

Any ideas on what the problem is ? It I know I am missing something simple but I cannot figure it out is it something like I will have to use boot::buffer ?

Thanks in advance

1
should you be using boost::asio::placeholders::error, and boost::asio::placeholders::bytes_transferred instead of err and buf.size() respectively?Chad
You also may need to wrap the last paremeter buf with boost::ref(buf).Chad

1 Answers

1
votes

To me it looks like, that all overloads of async_read_until() takes 2 arguments. You pass a function with 3 arguments. Likely you want to pass the stream as extra parameter, bind it to the function to get a function with 2 arguments.

boost::bind( &tcpReader::handle_read, this, _1, _2, boost::ref( buf ) )

Will "convert" your member function to something, that takes 2 arguments. The boost::ref() wraps your buffer as reference, otherwise a copy would be made.

Kind regards Torsten