views:

73

answers:

1

This line of code compiles correctly without a problem:

boost::bind(boost::ref(connected_),
            boost::dynamic_pointer_cast<session<version> >(shared_from_this()),
            boost::asio::placeholders::error);

However when assigning it to a boost::function or as a callback like this:

socket_->async_connect(connection_->remote_endpoint(),
                      boost::bind(boost::ref(connected_),
                      boost::dynamic_pointer_cast<session<version> >(shared_from_this()),
                      boost::asio::placeholders::error));

I'm getting a whole bunch of incomprehensible errors (linked since it's too long to fit here).

On the other hand I have succeeded binding a free signal to a boost::function like this:

void print(const boost::system::error_code& error)
{
    cout << "session connected";
}

int main()
{
boost::signal<void(const boost::system::error_code &)> connected_;
connected_.connect(boost::bind(&print, boost::asio::placeholders::error));

    client<>::connection_t::socket_ptr socket_(new client<>::connection_t::socket_t(conn->service())); // shared_ptr of a tcp socket

    socket_->async_connect(conn->remote_endpoint(),
                       boost::bind(boost::ref(connected_),
                       boost::asio::placeholders::error));
    conn->service().run(); // io_service.run()
    return 0;
}

This works and prints session connected correctly. What am I doing wrong here?

A: 

Have you read through the bind troubleshooting guide? I'm not familiar with your compiler, but your error seems similar to the second bullet in the troubleshooting section "The function object cannot be called with the specified arguments."

Sam Miller