我想为 async_write 提供一个额外的 boost::function。我希望首先调用连接自己的 HandleWrite 函数,然后调用提供的 boost::function。
Connection 的成员方法绑定到 asio async_write
void Connection::HandleWrite( const boost::system::error_code& e, boost::function<void (const boost::system::error_code&)> handler) { // Code removed for clarity if(!handler.empty()) handler(e); };
尝试将 HandleWrite 绑定到 asio async_write 并提供另一个绑定作为处理程序的值。这不编译。我究竟做错了什么?
void Connection::QueueRequest( boost::shared_array<char> message, std::size_t size, boost::function<void (const boost::system::error_code&)> handler) { // Code hidden for clarity boost::asio::async_write(m_Socket, boost::asio::buffer(buffer), boost::bind(&Connection::HandleWrite, shared_from_this(), boost::asio::placeholders::error, handler ) ); }
我从编译器得到的错误信息如下:
Error 1 error C2825: 'F': must be a class or namespace when followed by '::' boost\bind\bind.hpp 69 Error 2 error C2039: 'result_type' : is not a member of '`global namespace'' boost\bind\bind.hpp 69 Error 3 error C2146: syntax error : missing ';' before identifier 'type' boost\bind\bind.hpp 69 Error 4 error C2208: 'boost::_bi::type' : no members defined using this type boost\bind\bind.hpp 69 Error 5 fatal error C1903: unable to recover from previous error(s); stopping compilation boost\bind\bind.hpp 69