What error do you get exactly? I don't see anything obvious in the code indicated in your question, so I cannot give you a direct answer.
However, Cornell’s answer questioned me because I thought that functors created by boost :: bind could take any number of arguments and simply ignore the extra ones.
So, I quickly hacked this to check:
#include <boost/asio.hpp> #include <boost/bind.hpp> #include <boost/shared_ptr.hpp> #include <boost/enable_shared_from_this.hpp> #include <boost/function.hpp> #include <string> #include <iostream> void Foo(const boost::system::error_code&) { // whatever } struct Client : boost::enable_shared_from_this<Client> { void HandleWrite( const boost::system::error_code& Err, boost::function<void(const boost::system::error_code&)> OtherHandler ) { std::cout << "MyHandler(" << Err << ")\n"; OtherHandler(Err); } void MakeTheCall(boost::function<void (const boost::system::error_code&)> Other) { using boost::asio::ip::tcp; // Of course, the scope and initialization of // io_service, sock and request are all wrong here, // as we're only interested in testing if the async_write // call below will compile. // Don't try to run this at home! boost::asio::io_service io_service; tcp::socket sock(io_service); boost::asio::streambuf request; boost::asio::async_write(sock, request, boost::bind(&Client::HandleWrite, shared_from_this(), boost::asio::placeholders::error, Other ) ); } }; int main() { boost::shared_ptr<Client> c; c->MakeTheCall(boost::bind(&Foo, _1)); return 0; }
which draws what I think you are trying to do.
As expected, it compiles, so comparing it with what you are actually doing can help you find the problem.
source share