'运算符[]'的Boost :: function错误模糊重载

时间:2010-02-26 01:10:28

标签: c++ function boost bind

我得到的完整错误是:

error: ambiguous overload for ‘operator[]’ in ‘a[boost::_bi::storage4<A1, A2, A3,     
boost::arg<I> >::a4_ [with A1 = boost::_bi::value<MsgProxy*>, A2 = boost::arg<1>, A3 = 
boost::arg<2>, int I = 3]]’

它引用了我所拥有的类的第116行,它是此函数中的boost :: bind调用:

// Dispatch a message onto all connected clients
void MsgProxy::dispatch_msg(t_ic_msg_shptr message) {
    deque<t_socket_shptr>::const_iterator iter = clientList_.begin();

    for(; iter != clientList_.end(); ++iter) {
        message->async_send(*iter,
                boost::bind(&MsgProxy::handle_dispatch, this, _1, _2, _3));
    }
}

作为参考,句柄调度功能如下所示:

// Called to handle result of saync_send command in dispatch_msg
void MsgProxy::handle_dispatch(t_ic_msg_shptr messsage, t_socket_shptr socket_ptr, 
                   const boost::system::error_code &error) {
    if (error) {
    RDEBUG("Error forwarding message onto clients -- %s",
           error.message().c_str());
    }
}

最后是被调用的async_send函数:

void async_send        (t_socket_shptr, t_icsend_callback);

t_icsend_callback是:

typedef boost::function<void (t_socket_shptr, const boost::system::error_code&)> 
                                                              t_icsend_callback;

基本上我有一个函数(async_send),它接受套接字发送消息, 以及一个回调(使用boost :: function定义)来异步报告状态。我正在尝试将成员绑定到boost :: function参数,但是boost似乎不喜欢我在这里做的事情。我一直在boost :: function和boost:bind文档上下来,在我看来这应该有用......我甚至有一个几乎完全相同的调用,这不会引发错误...颜色我难住了。

1 个答案:

答案 0 :(得分:2)

t_icsend_callback是一个需要2个agruments的函数。

boost::bind(&MsgProxy::handle_dispatch, this, _1, _2, _3)

返回一个带3个参数的函数。

我想你想说

   message->async_send(*iter,
            boost::bind(&MsgProxy::handle_dispatch, this, message, _1, _2));

(注意“消息”作为第一个有界参数)。

相关问题