本文整理汇总了C++中EventDispatcher::addHandler方法的典型用法代码示例。如果您正苦于以下问题:C++ EventDispatcher::addHandler方法的具体用法?C++ EventDispatcher::addHandler怎么用?C++ EventDispatcher::addHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventDispatcher
的用法示例。
在下文中一共展示了EventDispatcher::addHandler方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
EventDispatcher dispatcher;
int my_var = 0;
dispatcher.addHandler("event1", [&my_var](EventDispatcher& ev) -> bool {
cout << "My event1 has been launched (first handler)" << endl;
my_var++;
return true;
});
dispatcher.addHandler("event1", [&my_var](EventDispatcher& ev) -> bool {
cout << "My event1 has been launched (second handler)" << endl;
my_var++;
cout << "Trigger event2..." << endl;
ev.dispatchEvent("event2");
return false;
});
dispatcher.addHandler("event2", [&my_var](EventDispatcher& ev) -> bool {
cout << "My event2 has been launched!" << endl;
my_var++;
return true;
});
cout << "Triggering event..." << endl;
dispatcher.dispatchEvent("event1");
cout << "My var is: " << my_var << endl;
return 0;
}