cocos2dx对CC_CALLBACK_*使用了std::bind进行函数适配
// new callbacks based on C++11
#define CC_CALLBACK_0(__selector__,__target__, ...) std::bind(&__selector__,__target__, ##__VA_ARGS__)
#define CC_CALLBACK_1(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, ##__VA_ARGS__)
#define CC_CALLBACK_2(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, std::placeholders::_2, ##__VA_ARGS__)
#define CC_CALLBACK_3(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, #

本文介绍了cocos2dx中使用CC_CALLBACK_*系列宏进行回调处理的方式,这些宏利用std::bind实现函数适配。回调函数指针(__selector__)与回调对象指针(__target__)结合,支持不同数量的不定参数,如CC_CALLBACK_0、CC_CALLBACK_1、CC_CALLBACK_2等,并可通过可变参数列表##__VA_ARGS__添加自定义参数。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



