ASYNC_WAIT处理程序班级成员具有取消处理
async_wait handler class member with cancellation handling
这很好:
class cStartSequence
{
void Tick()
{
// do something
}
void Wait()
{
myTimer->expires_from_now(
boost::posix_time::seconds( mySecs ) );
myTimer->async_wait(boost::bind(
&cStartSequence::Tick,
this
));
}
...
};
我希望能够取消计时器并让处理程序做一些不同的事情
void Tick( boost::system::error_code & ec )
{
if( ! ec )
// do something
else
// do something different
}
问题是如何修改呼叫async_wait?
这不编译
myTimer->async_wait(boost::bind(
&cStartSequence::Tick,
this,
boost::asio::placeholders::error
));
编译器投诉:
C:UsersJamescodeboostv1_63boostbindbind.hpp|319|error:
no match for call to
'(boost::_mfi::mf1<void, pinmed::wrs::cStartSequence, boost::system::error_code&>)
(pinmed::wrs::cStartSequence*&, const boost::system::error_code&)'
我在Async_wait参数上尝试了一些变体,但没有运气。
Boost:ASIO V1.63,Windows 10,Code :: Blocks V16.01
您的tick方法获取非const参考。没关系(并且不满足处理程序要求)。使用
void Tick(boost::system::error_code const& ec);
或也许
void Tick(boost::system::error_code ec);
出于略有模糊的原因(特定于图书馆的优化IIRC),ASIO作者首选第一个。
ps。有关安全取消截止时间计时器,请参见
- 取消deadline_timer,无论如何都触发回调
- 与悬挂式的Coroutine正确清理
相关文章:
- 找不到成员对象:没有名为get_event()的成员,也处理多态性和向量
- C++交换来自同一类成员的参数值,处理多个类
- Visual C++: MSVC vs. GCC+CLANG: 处理 lambda 捕获类成员变量,正确的方法是什么?
- 处理类内的回调时,必须调用对非静态成员函数的引用
- C++预处理会生成变量成员、资源库和映射
- 如何处理运算符=中的常量成员?
- 多线程处理中的静态成员变量
- 类成员作为 C++ 中 C 样式事件的事件处理程序
- 如何处理具有不同类的成员函数的函数查找表?
- 在字符串类上的成员函数和out_of_range异常处理
- 如何处理算法中具有不同名称成员函数的类?
- C++执行期间的类成员函数错误/异常处理
- 在类声明中处理指向成员函数的指针
- 同时处理非成员函数指针和成员函数指针
- 如何在 Arduino 中使用 C++ 成员函数作为中断处理程序?
- 为什么调用单例类 Qt 消息处理程序成员函数会出现错误:缺少参数列表
- 我应该如何处理:错误 C2039 "分配":不是 Visual Studio 2017 中"cl::string"的成员?
- 在多个继承的情况下,C 编译器如何处理成员变量内存偏移
- 我如何处理成员的所有派生动态内存
- std::bind如何处理成员函数