我正在尝试绑定一个读取处理程序,而提升asio让我发疯。
我有以下课程
class namenode_registration:
public boost::enable_shared_from_this<namenode_registration>,
private boost::noncopyable {
private:
[...]
public:
namenode_registration(....);
[...]
void handle_request_sent(const boost::system::error_code& e);
void handle_read_reply_type(boost::asio::mutable_buffers_1& buffer,
const boost::system::error_code& e, std::size_t bytes_transferred);
};
通过以下实施:
void namenode_registration::handle_request_sent(
const boost::system::error_code& e) {
if (!e) {
boost::asio::async_read(socket_,
boost::asio::buffer(buffer_data_, namenode::reply::type_size),
boost::bind(&namenode_registration::handle_read_reply_type,
shared_from_this(), boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
}
}
我真的不明白为什么不编译:
In file included from /usr/include/boost/bind.hpp:22:0,
from /home/.../datanode/namenode_registration.cpp:9:
/usr/include/boost/bind/bind.hpp:
In instantiation of ‘boost::_bi::result_traits<boost::_bi::unspecified,
void (datanode::namenode_registration::*)(boost::asio::mutable_buffers_1&,
const boost::system::error_code&, long unsigned int)>’:
/usr/include/boost/bind/bind_template.hpp:15:48:
instantiated from ‘boost::_bi::bind_t<boost::_bi::unspecified, void (datanode::namenode_registration::*
(boost::asio::mutable_buffers_1&, const boost::system::error_code&, long unsigned int),
boost::_bi::list3<boost::_bi::value<boost::shared_ptr<datanode::namenode_registration> >,
boost::arg<1> (*)(), boost::arg<2> (*)()> >’
/home/.../datanode/namenode_registration.cpp:50:51:
instantiated from here
/usr/include/boost/bind/bind.hpp:69:37:
erreur: ‘void (datanode::namenode_registration::*)(boost::asio::mutable_buffers_1&,
const boost::system::error_code&, long unsigned int)’ is not a class, struct, or union type
答案 0 :(得分:4)
你没有为这个函数绑定足够的参数:
void handle_read_reply_type(boost::asio::mutable_buffers_1& buffer,
const boost::system::error_code& e, std::size_t bytes_transferred);
你错过了缓冲区参数:
boost::bind(&namenode_registration::handle_read_reply_type,
shared_from_this(), boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));