Boost Asio async_wait 处理程序

发布于 2024-10-07 04:29:43 字数 568 浏览 0 评论 0 原文

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

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

我如何定义一个采用 const boost::system::error_code& 的处理程序? error 以及一个 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

谢谢。

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

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

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

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱娆 2024-10-14 04:29:43

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

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

这里,将使用 0 作为第一个参数来调用处理程序,并且将仅将 error_code 作为第二个参数转发。

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文