我得到的完整错误是这样的:
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 定义)。我试图将一个成员绑定(bind)到那个 boost::function 参数,但 boost 似乎不喜欢我在这里做的事情。我一直在 boost::function 和 boost:bind 文档上下 float ,在我看来这应该可行......我什至有一个几乎完全相同的调用,没有抛出错误......给我上色难倒了。
最佳答案
t_icsend_callback 是一个接受 2 个参数的函数。
boost::bind(&MsgProxy::handle_dispatch, this, _1, _2, _3)
返回一个接受 3 个参数的函数。
我想你想说
message->async_send(*iter,
boost::bind(&MsgProxy::handle_dispatch, this, message, _1, _2));
(注意“消息”是第一个有界参数)。
关于c++ - Boost::‘operator[]’ 的函数错误模糊重载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2338875/