coco2d-x中成员函数回调实现原理
来源:互联网 发布:linux 线程同步机制 编辑:程序博客网 时间:2024/06/06 14:06
//头文件
#ifndef __COOCS2D_CALLBACK_H__ #define __COOCS2D_CALLBACK_H__ #include <iostream> #include <string> using namespace std; // 基类 class Person { public: void name(string name); }; // 定义基类的成员函数指针 typedef void (Person::*SEL_CallFun)(string str); #define callFunc_selector(_SELECTOR) (SEL_CallFun)(&_SELECTOR)// 派生类 class Student : public Person{ private: string m_name; int m_age; public: Student(string name, int age); ~Student(); // 回调 void callBack(string str); // say方法,要调用回调函数。 void say(); protected: // 回调的执行者 Person *m_pListen; // 回调函数指针 SEL_CallFun m_pfnSelectior; }; #endif
//cpp文件
#include "cocos2dx_callback.h"void Person::name(string name) { cout<<name<<endl; } Student::Student(string name, int age) { this->m_name = name; this->m_age = age; } Student::~Student() { } void Student::say() { cout<<"Hi this is a Student"<<endl; // 回调函数指针赋值。需要强转成 SEL_CallFun //m_pfnSelectior = (SEL_CallFun)(&Student::callBack); m_pfnSelectior = callFunc_selector(Student::callBack);// 回调的执行对象,传this m_pListen = this; // 调用回调,参数是个string (m_pListen->*m_pfnSelectior)(m_name); } // 成员函数,要回调的函数 void Student::callBack(string str) { cout<<"My name is " << str<<endl << "age is " <<m_age<<endl; }
//main函数
#include <iostream> #include "cocos2dx_callback.h"int main(int argc, const char * argv[]) { Student *a = new Student("Join",20); a->say(); system("pause");return 0; }
- coco2d-x中成员函数回调实现原理
- COCO2D-X中ScrollView的使用实现
- CPP中函数编译原理和成员函数的实现
- coco2d-x 3.x 实现帧动画
- cocos2d-x中函数回调 事件监听机制详细解析 涉及c++成员函数指针
- coco2d-x 实现风雪飘动效果
- coco2d-x 实现风雪飘动效果
- coco2d-x CCScrollView实现背包翻页,仅供参考
- coco2d-x 皮球弹跳翻案实现
- coco2d-x CCScrollView实现背包翻页,仅供参考
- coco2d-x CCScrollView实现背包翻页
- coco2d-x单例的实现
- coco2d-x 中box2d选中刚体
- 如何在类中实现回调成员函数
- 如何在类中实现回调成员函数
- MFC CString类成员函数实现原理
- coco2d-x CCScrollView实现关卡选择 新手引导 帮助界面
- coco2d-x 2.0.4 帧动画 两种实现方式
- 【转载】种子搜索神器下载官网,最新版种子搜索器 p2p bt迅雷种子搜索器
- 淮阴师范CSDN高校俱乐部招贤纳才了!!!
- 扩展方法
- webservice加密,通过SoapHeader来增强Web Service的安全性
- Basic English (基本英语)
- coco2d-x中成员函数回调实现原理
- 英语口语场景-----问路篇
- js正则积累
- 前端开发利器—FIDDLER
- Web图表开发-用ChartDirector画极线图
- WCF学习(一):实例
- oracle 树结构数据层次分列显示
- MIPS 平台下 I/O 端口的读写--以龙芯为例
- Android之Adapter用法总结