Boost::function错误:'operator[]'的重载模糊

3

The full error I'm getting is this:

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个回答

2

t_icsend_callback是一个带有两个参数的函数。

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

返回一个接受3个参数的函数。

我认为你想表达的是

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

(将“message”作为第一个受限参数)。


1
哦,我真是个笨蛋,我应该早点看到的。谢谢你的鹰眼。很抱歉回复这么晚,我在桌锯上撞了手指,不得不去急诊室绕路了。 - gct

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接