c++ - Boost::‘operator[]’ 的函数错误模糊重载

标签 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 定义)。我试图将一个成员绑定(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/

相关文章:

javascript - 向 "Virtual pet"游戏添加了功能,但我找不到我的错误

c++ - "detects_simple_anagram": memory access violation at address 0x00000000: no mapping at fault address 中的 fatal error

c++ - boost 共享内存操作c++

java - Azure函数:Java How to accept content-type of application/xml then convert it to a POJO

c++ - 我如何使用 Boost Random

c++ - 使用 Ollydbg 编辑程序

c++ - 错误 : template parameter redeclared here as 'false' . 一些模板魔法

c++ - 在 vector 中放置派生的可移动但不可复制会产生编译错误

c++ - 为什么这段 C++ 代码没有从堆中删除对象?

c++ - 使用递归获取变量的奇怪值