Debian Linux,Boost 1.67。以在boost :: asio :: posix :: stream_descriptor :: async_wait上进行编码的boost为例,并在类中放置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个线程中调用此例程,因此不能将其声明为静态,这仅是对错误消息的一种建议。