在完成处理程序中增加绑定错误

时间:2013-05-03 05:02:26

标签: c++ boost boost-asio boost-bind

我遇到了绑定错误

/usr/local/include/boost/bind/bind.hpp:457:错误:无效使用void表达式

我的程序是关于使用回调处理程序的异步操作,如下所示:

template<typename Handler>
void async_monitor(Handler handler) {
    stream_descriptor_.async_read_some(
            boost::asio::buffer(read_buffer_),
            boost::bind(&dir_monitor_impl::handle_monitor<Handler>, shared_from_this(),
                    boost::asio::placeholders::error,
                    boost::asio::placeholders::bytes_transferred,
                    handler));
}//IF I remove this code, the compilation success

处理程序声明:

template<typename Handler>
void handle_monitor(boost::system::error_code &ec,
        std::size_t bytes_transferred, Handler handler){
}

最后,这些异步动作用作以下内容:

template <typename Handler> 
void start_async_monitor(implementation_type &impl, Handler handler) 
{ 
    //this->async_monitor_io_service_.post(monitor_operation<Handler>(impl, this->get_io_service(), handler));
    impl->async_monitor(handler);
}

你能帮我解释一下这个错误吗,非常感谢!

1 个答案:

答案 0 :(得分:2)

处理程序签名必须如下(注意 const ):

void handle_monitor(const boost::system::error_code &ec, std::size_t bytes_transferred, Handler handler)

相关问题