C++ 异步写入方法错误
它应该像这样工作。但是,当我尝试构建项目时,我会出现以下错误C++ 异步写入方法错误,c++,boost-asio,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)); } 我甚至没有使用“F”为什
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));
}
我甚至没有使用“F”为什么它总是说“F”:当后跟“:”时必须是类或命名空间
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
应该是
boost::bind(&Chat:Send, this,boost::asio::placeholders::error));
^^^^^^
注意classChat
的范围解析运算符。使用boost::bind
时可能遇到的编译器错误非常令人困惑。void Connection::Send(uint8\u t*buffer,int-length){boost::asio::async\u write(socket,boost::asio::buffer(buffer,length),boost::bind(&Connection::handler,this,boost::asio::占位符::error,boost::asio::占位符::bytes_transfer));}无效连接::handler(const boost::system::error_code&error,std::size_t bytes_transfer){}
我这样做了,它工作了,但这是解决这个问题的正确方法吗?
boost::bind(&Chat::Send, this,boost::asio::placeholders::error));
^^^^^^