在 stream_descriptor::async_wait 中无效使用非静态成员函数

invalid use of non-static member function in stream_descriptor::async_wait

本文关键字:静态成员 函数 无效 wait stream descriptor async      更新时间:2023-10-16

Debian Linux, Boost 1.67. 以编码 boost::asio::p osix::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::p osix::stream_descriptor::wait_read, boost::bind(&EHandler::wait_handler, this, boost::asio::p laceholders::error((;