c++ - 在 stream_descriptor::async_wait 中无效使用非静态成员函数
问题描述
Debian Linux,升压 1.67。以 boost on encoding boost::asio::posix::stream_descriptor::async_wait 为例,并将其放入一个类中,我在 async_wait 行的 wait_handler 上得到“无效使用非静态成员函数”。
提升示例
void wait_handler(const boost::system::error_code& error)
{
if (!error)
{
// Wait succeeded.
}
}
...
boost::asio::posix::stream_descriptor descriptor(io_context);
...
descriptor.async_wait(
boost::asio::posix::stream_descriptor::wait_read,
wait_handler);
转换成
void EHandler::wait_handler(const boost::system::error_code& error)
{
if (!error)
{
// Wait succeeded.
}
}
void EHandler::StartRead()
{
...
boost::asio::posix::stream_descriptor descriptor(io_context);
descriptor.async_wait(boost::asio::posix::stream_descriptor::wait_read, wait_handler);
}
试过:
... wait_handler, this);
... EHandler::wait_handler);
... &EHandler::wait_handler);
... EHandler::wait_handler, this);
... &EHandler::wait_handler, this);
... boost::bind() with each of the above options
甚至尝试将 _1) 添加到每个。我在看什么?
由于此例程将被最多 8 个线程调用,因此不能将其声明为静态,这只是对错误消息解决方案的建议。
解决方案
尚未完全测试,这只是通过编译器错误。
descriptor.async_wait(boost::asio::posix::stream_descriptor::wait_read, boost::bind(&EHandler::wait_handler, this, boost::asio::placeholders::error));
推荐阅读
- php - 如何在 Wordpress 上启用 curl
- javascript - 检测不同系统和键盘上键入的键的最佳方法?Chrome 手机键码错误
- android - MaterialButtonToggleGroup 孩子的 MaterialButton layout_marginStart, layout_marginEnd 不起作用
- php - Wordpress NGINX Plesk 重写规则 + 重写特定文件夹
- xpath - 从 beautifulsoup 切换到 htmlelement - 如何查找元素
- php - 父类不使用flock函数锁定文件
- options - Cplex 仅在根处切割
- html - 仅 CSS / 在选中的单选按钮上显示多个 div
- css - 关于在 CSS url() 中使用数据 URI 的有效性的说明
- memory - WildFly 17.0.1.Final 堆内存问题