2011-05-22 59 views
1
void Chat::Send(uint8_t* buffer, int length){ 
     boost::asio::async_write(socket_,boost::asio::buffer(buffer,length), 
      boost::bind(&Chat:Send, this,boost::asio::placeholders::error)); 
} 

它應該像this tutorial一樣工作。但是,當我嘗試async_write方法錯誤

Error 1 error C2825: 'F': must be a class or namespace when followed by '::' e:\boost_1_46_1\boost_1_46_1\boost\bind\bind.hpp 69 
Error 2 error C2039: 'result_type' : is not a member of '`global namespace'' e:\boost_1_46_1\boost_1_46_1\boost\bind\bind.hpp 69 
Error 3 error C2146: syntax error : missing ';' before identifier 'type' e:\boost_1_46_1\boost_1_46_1\boost\bind\bind.hpp 69 
Error 4 error C2208: 'boost::_bi::type' : no members defined using this type e:\boost_1_46_1\boost_1_46_1\boost\bind\bind.hpp 69 
Error 5 error C1903: unable to recover from previous error(s); stopping compilation e:\boost_1_46_1\boost_1_46_1\boost\bind\bind.hpp 69 

我甚至不使用「F」爲什麼它一直在說「F」打造的項目,我得到了以下錯誤:其次是當「::」必須是類或命名空間?

+0

'空隙連接::發送(uint8_t *緩衝液,INT長度){ \t升壓:: ASIO :: ASYNC_WRITE(socket_,升壓:: ASIO ::緩衝液(緩衝液,長度), 升壓::綁定( &Connection :: handler,this,boost :: asio :: placeholders :: error,boost :: asio :: placeholders :: bytes_transferred)); } 無效連接::處理器(常量的boost ::系統:: ERROR_CODE和錯誤,的std ::爲size_t bytes_transferred){} ' 我做出這樣說,這和它的工作,但是,正確的解決這問題? – pro4ever 2011-05-22 13:59:18

回答

3
boost::bind(&Chat:Send, this,boost::asio::placeholders::error)); 
       ^^^^^^ 

應該

boost::bind(&Chat::Send, this,boost::asio::placeholders::error)); 
       ^^^^^^ 

音符範圍解析運營商Chat類。使用boost::bind時可能遇到的編譯器錯誤非常混亂。

+0

+1非常好斑點:) – 2011-05-22 14:05:38