簡體   English   中英

boost:asio:read_until與boost :: bind有關的問題

[英]boost:asio:read_until issue with boost::bind

我在編譯這段代碼錯誤時遇到問題

/usr/include/boost/bind/bind_mf_cc.hpp:91:5:錯誤:初始化'boost :: _ bi :: bind_t的參數5,類型名boost :: _ bi :: list_av_4 :: type> boost :: bind(R (T :: *)(B1,B2,B3),A1,A2,A3,A4)[其中R =無效; T = tcpReader; B1 = const boost :: system :: error_code&; B2 =無符號整數; B3 = boost :: asio :: basic_streambuf <>&; A1 = tcpReader *; A2 = boost :: system :: error_code; A3 =無符號整數; A4 = boost :: asio :: basic_streambuf <>; 類型名稱boost :: _ bi :: list_av_4 :: type = boost :: _ bi :: list4,boost :: _ bi :: value,boost :: _ bi :: value,boost :: _ bi :: value>>]

void tcpReader::handle_read(const boost::system::error_code& ec, std::size_t bytes_transferred, boost::asio::streambuf& buf)
// inside a class method
boost::asio::streambuf buf;
boost::asio::async_read_until(*sock,buf,"\n" ,
                              boost::bind(&tcpReader::handle_read,this,error,buf.size(),buf)
                              );

關於問題是什么? 我知道我缺少一些簡單的東西,但是我無法弄清楚是否需要使用boot :: buffer嗎?

提前致謝

在我看來,async_read_until()的所有重載都帶有2個參數。 您傳遞帶有3個參數的函數。 可能您想將流作為附加參數傳遞,將其綁定到函數以獲取具有2個參數的函數。

boost::bind( &tcpReader::handle_read, this, _1, _2, boost::ref( buf ) )

將您的成員函數“轉換”為需要2個參數的東西。 boost :: ref()將緩沖區包裝為引用,否則將進行復制。

親切的問候托爾斯滕

暫無
暫無

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

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