boost async_wait and adding “this” in a bind [duplicate]

孤街浪徒 提交于 2019-12-06 16:48:29

void handler::message() is a non-static member-function, as such it must be invoked on an object of type handler (or a derived type thereof).

This further means that we must say on which object this member-function is to be invoked when trying to pass it as a callback to some other function.

m_timer.async_wait(boost::bind(&handler::message,    this));
//                             ^- call this function ^- on this object

By passing this to boost::bind as you have shown, we express that we would like to invoke the member-function, who's address is &handler::message, on the current object (ie. this).


Note: The whole expression is equivalent telling m_timer.async_wait to call this->handler::message() (or this->message() for short).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!