async_write方法错误

时间:2011-05-22 13:47:25

标签: c++ boost-asio

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一样工作。但是当我尝试构建项目时,我得到以下错误

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':当后跟'::'时必须是一个类或命名空间?

1 个答案:

答案 0 :(得分:3)

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

应该是

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

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