欢迎转载:http://blog.csdn.net/fylz1125/article/details/8546607
cocos2d-x中有大量的回调函数的应用,主要有以下几类,看下CCObject.h中的定义
- typedefvoid(CCObject::*SEL_SCHEDULE)(float);//用来调update
- typedefvoid(CCObject::*SEL_CallFunc)();//用来自定义无参回调
- typedefvoid(CCObject::*SEL_CallFuncN)(CCNode*);//带执行者回调
- typedefvoid(CCObject::*SEL_CallFuncND)(CCNode*,void*);//带一个自定参数的回调
- typedefvoid(CCObject::*SEL_CallFuncO)(CCObject*);
- typedefvoid(CCObject::*SEL_MenuHandler)(CCObject*);
- typedefvoid(CCObject::*SEL_EventHandler)(CCEvent*);
- typedefint(CCObject::*SEL_Compare)(CCObject*);
- #defineschedule_selector(_SELECTOR)(SEL_SCHEDULE)(&_SELECTOR)
- #definecallfunc_selector(_SELECTOR)(SEL_CallFunc)(&_SELECTOR)
- #definecallfuncN_selector(_SELECTOR)(SEL_CallFuncN)(&_SELECTOR)
- #definecallfuncND_selector(_SELECTOR)(SEL_CallFuncND)(&_SELECTOR)
- #definecallfuncO_selector(_SELECTOR)(SEL_CallFuncO)(&_SELECTOR)
- #definemenu_selector(_SELECTOR)(SEL_MenuHandler)(&_SELECTOR)
- #defineevent_selector(_SELECTOR)(SEL_EventHandler)(&_SELECTOR)
- #definecompare_selector(_SELECTOR)(SEL_Compare)(&_SELECTOR)
本质上,就是函数指针的应用。
但是,我们知道,在C中,函数指针是很普遍的应用。一般函数的函数名就是指针,不过是常量,再定义一个函数指针就是一个变量,这个变量可以指向这一类函数的地址。
比如: