回调函数实现类似QT中信号机制
1. 定义回调接口类:
- class UIcallBack
- {
- public:
- virtual void onAppActivated() = 0;
- virtual void onShowMore() = 0;
- };
2. 定义一个类 继承 回调接口类,并包含你要监听的类
- class AppManager : public UIcallBack
- {
- public:
- AppManager();
- UIManager uiManager;
- ……
- uiManager.setCallBack(this);
- void AppManager::onAppActivated()
- {
- }
- void AppManager::onShowMore()
- {
- _D("callback onshowMore\n");
- }
3. 要监听的类实现
- class UIManager
- {
- public:
- UIManager();
- ~UIManager();
- void setCallBack(UIcallBack *pcallBack)
- {
- m_pcallBack = pcallBack;
- }
- UIcallBack *m_pcallBack;
- };
在 UIManager里调用
- m_pcallBack->onShowMore();
则在AppManager类里就能响应到onShowMore()这个消息
http://blog.csdn.net/liukang325/article/details/45742675