簡體   English   中英

'運算符[]'的Boost :: function錯誤模糊重載

[英]Boost::function error ambiguous overload for ‘operator[]’

我得到的完整錯誤是這樣的:

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文檔上下來,在我看來這應該有用......我甚至有一個幾乎完全相同的調用,這不會引發錯誤...顏色我難倒。

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));

(注意“消息”作為第一個有界參數)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM