提高:: io_service对象::后函数内绑定组成 [英] boost::bind composition inside io_service::post function
本文介绍了提高:: io_service对象::后函数内绑定组成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑下面的类
类task_counter
{
上市:
task_counter(短,提高:: ASIO :: io_service对象和放大器;);
〜task_counter(无效);
模板< typename的CompletionHandler>
无效exec_task(CompletionHandler处理)
{
授予访问权限();
io_.post(升压::绑定(安培; task_counter :: exec_and_decrease_counter< CompletionHandler>中这一点,处理程序));
} 模板< typename的CompletionHandler>
无效exec_and_decrease_counter(CompletionHandler处理)
{
处理程序();
decrease_counter();
} 私人的:
....
}
方法exec_task通过这种方式另一类称为:
tc_msg-> exec_task(的boost ::绑定(安培; message_receiver :: HANDLE_MSG,对此,味精));
编译失败在bind.hpp指出无效使用作废前pression的
我搞清楚这个问题应该是io_post函数,其参数是两个不同的boost ::绑定对象的组成里面。但我无法通过现实问题深深地去了。
解决方案
而不是:
<$p$p><$c$c>io_.post(boost::bind(&task_counter::exec_and_decrease_counter<CompletionHandler>,这一点,处理程序));请尝试以下操作:
的#include&LT;升压/绑定/ protect.hpp&GT;
// ...io_.post(boost::bind(&task_counter::exec_and_decrease_counter<boost::_bi::protected_bind_t<CompletionHandler> &gt;中此,提振::保护(处理)));
Given the following class
class task_counter
{
public:
task_counter(short, boost::asio::io_service&);
~task_counter(void);
template<typename CompletionHandler>
void exec_task(CompletionHandler handler)
{
grant_access();
io_.post(boost::bind(&task_counter::exec_and_decrease_counter<CompletionHandler>, this, handler));
}
template<typename CompletionHandler>
void exec_and_decrease_counter(CompletionHandler handler)
{
handler();
decrease_counter();
}
private:
....
}
Method exec_task is called by another class in this way:
tc_msg->exec_task(boost::bind(&message_receiver::handle_msg, this, msg));
Compilation fails stating "invalid use of void expression" in bind.hpp I'm figuring out that the problem should be inside the io_post function whose argument is a composition of two different boost::bind objects. But I was unable to go deeply through the real problem.
解决方案
Instead of:
io_.post(boost::bind(&task_counter::exec_and_decrease_counter<CompletionHandler>, this, handler));
Try the following:
#include <boost/bind/protect.hpp>
//...
io_.post(boost::bind(&task_counter::exec_and_decrease_counter<boost::_bi::protected_bind_t<CompletionHandler> >, this, boost::protect(handler)));
这篇关于提高:: io_service对象::后函数内绑定组成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文