Boost Asio async_wait处理程序 [英] Boost Asio async_wait handler

查看:1448
本文介绍了Boost Asio async_wait处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

boost asio deadline_timer async_wait 函数采用以下形式的处理程序:

The boost asio deadline_timer async_wait function is taking handler of the form :

void handler(const boost::system::error_code& error)

我如何定义一个处理程序,它接受 const boost :: system :: error_code&错误以及类型 int

How could I define a handler which takes in const boost::system::error_code& error and also an argument of type int ?

boost::asio::deadline_timer t(io_service);

t.async_wait(handler); //I need the async_wait to take in handler which accepts argument boost::system::error_code& error and an int 

void handler(int, const boost::system::error_code& error )//extra int argument

谢谢。

推荐答案

您可以使用 Boost.Bind 为第一个参数提供值:

You could use Boost.Bind to provide a value for the first argument :

t.async_wait(boost::bind(handler, 0, _1));

这里,处理程序将调用0作为其第一个参数, error_code 将只作为第二个参数转发。

Here, the handler will be called with a 0 as its first argument and the error_code will simply be forwarded as a second argument.

这篇关于Boost Asio async_wait处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆