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”:后跟“::”时必须是类或命名空间?
最佳答案
boost::bind(&Chat:Send, this,boost::asio::placeholders::error));
^^^^^^
应该是
boost::bind(&Chat::Send, this,boost::asio::placeholders::error));
^^^^^^
请注意类 Chat
的范围解析运算符。使用 boost::bind
时可能遇到的编译器错误非常令人困惑。
关于c++ - async_write 方法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6088315/