c++ - async_write 方法错误

标签 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”:后跟“::”时必须是类或命名空间?

最佳答案

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/

相关文章:

c++ - 错误 : base class 'A1' has private copy constructor

c++ - 使用 N-API 将数据流式传输到 Node.js C++ 插件

c++ - 发送大数据时增强数据包之间丢失的asio tcp数据

C++ lambda,没有看到函数和参数?

c++ - 发送UDP包时"Invalid argument",但是哪个呢?

c++ - C++ 中的非类型模板参数可以使用大括号初始值设定项吗?

c++ - 取消或只是适本地阻止套接字上的任何 future 异步操作

c++ - 来自其他类的 asio 计时器

c++ - boost asio serial_port_service 和 serial_port 有什么区别

python - C++ 中的 Cprofile(Python)?