开发者

Boost Asio async_wait handler

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_serv开发者_如何学编程ice);

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜