We have a member function in some .h file
template <typename MutableBufferSequence>
int read_some(boost::asio::ip::tcp::socket& sock,
const MutableBufferSequence& buffers)
{
return sock.read_some(buffers);
}
And such code we want to have in one of our class functions:
boost::packaged_task<int> pt(boost::bind(&http_request::read_some, this, &socket, boost::asio::buffer(buffer, buffer_size)));
This gives me 87 compiler errors and talls me that boost::bind does not work this way. I wonder how to pass boost::asio::buffer
via boost::bind
to my function?
You have to tell the compiler which read_some
you want to bind. Since it's a template, you have to specify the template parameter when you pass it in to bind()
.
In your case you want http_request::read_some<boost::asio::mutable_buffers_1>
.
As a side note, you're also passing in the socket object itself wrong. You're passing in a pointer to the socket, and the function takes a reference. Instead of passing in &socket
to bind
, pass in boost::ref(socket)
, alternatively you can make the function take a socket pointer instead of reference.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.