async_write方法错误

async_write method error

本文关键字:错误 方法 write async      更新时间:2023-10-16
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));
}

它应该像本教程一样工作。但是当我尝试构建项目时,出现以下错误

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

我什至没有使用"F",为什么它一直说"F":后跟"::"时必须是类或命名空间?

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

应该是

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

请注意类 Chat 的范围解析运算符。使用boost::bind时可能遇到的编译器错误非常令人困惑。