这里加入一个插曲,是关于Cocos2d-x回调函数的。首先,让我们Cocos支持的回调函数宏有哪些,以及其原型:

// 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, ##__VA_ARGS__)

右上边,以上共4个回调函数宏。都是通过C++11新增加bind()实现的。原型如下:

template <class Fn, class... Args>
/* unspecified */ bind (Fn&& fn, Args&&... args);
with return type ()
template <class Ret, class Fn, class... Args>
/* unspecified */ bind (Fn&& fn, Args&&... args);

使用如下,见http://www.cplusplus.com/reference/functional/bind/?kw=bind

// bind example
#include <iostream> // std::cout
#include <functional> // std::bind // a function: (also works with function object: std::divides<double> my_divide;)
double my_divide (double x, double y) {return x/y;} struct MyPair {
double a,b;
double multiply() {return a*b;}
}; int main () {
using namespace std::placeholders; // adds visibility of _1, _2, _3,... // binding functions:
auto fn_five = std::bind (my_divide,,); // returns 10/2
std::cout << fn_five() << '\n'; // auto fn_half = std::bind (my_divide,_1,); // returns x/2
std::cout << fn_half() << '\n'; // auto fn_invert = std::bind (my_divide,_2,_1); // returns y/x
std::cout << fn_invert(,) << '\n'; // 0.2 auto fn_rounding = std::bind<int> (my_divide,_1,_2); // returns int(x/y)
std::cout << fn_rounding(,) << '\n'; // MyPair ten_two {,}; // binding members:
auto bound_member_fn = std::bind (&MyPair::multiply,_1); // returns x.multiply()
std::cout << bound_member_fn(ten_two) << '\n'; // auto bound_member_data = std::bind (&MyPair::a,ten_two); // returns ten_two.a
std::cout << bound_member_data() << '\n'; // return ;
}

关于##__VA_ARGS__见博客地址:http://www.cnblogs.com/zhujudah/archive/2012/03/22/2411240.html

至于__selector__和__target__应该是cocos自定义的东西;我在c99、c11中没有找到对应的东西。

而关于placehoders命名空间内容如下:

namespace placeholders
{
extern /* unspecified */ _1;
extern /* unspecified */ _2;
extern /* unspecified */ _3;
// ...
}

Cocos2d-x学习笔记(十)CC_CALLBACK回调函数相关宏的更多相关文章

  1. JavaScript学习笔记(十二) 回调模式(Callback Pattern)

    函数就是对象,所以他们可以作为一个参数传递给其它函数: 当你将introduceBugs()作为一个参数传递给writeCode(),然后在某个时间点,writeCode()有可能执行(调用)intr ...

  2. go微服务框架kratos学习笔记十(熔断器)

    目录 go微服务框架kratos学习笔记十(熔断器) 什么是熔断 熔断器逻辑 kratos Breaker kratos 熔断逻辑 kratos熔断器使用说明 bladmaster client br ...

  3. python3.4学习笔记(十四) 网络爬虫实例代码,抓取新浪爱彩双色球开奖数据实例

    python3.4学习笔记(十四) 网络爬虫实例代码,抓取新浪爱彩双色球开奖数据实例 新浪爱彩双色球开奖数据URL:http://zst.aicai.com/ssq/openInfo/ 最终输出结果格 ...

  4. Learning ROS for Robotics Programming Second Edition学习笔记(十) indigo Gazebo rviz slam navigation

    中文译著已经出版,详情请参考:http://blog.csdn.net/ZhangRelay/article/category/6506865 moveit是书的最后一章,由于对机械臂完全不知,看不懂 ...

  5. MOOS学习笔记2——HelloWorld回调

    MOOS学习笔记2--HelloWorld回调 例程 #include "MOOS/libMOOS/Comms/MOOSAsyncCommClient.h" bool OnConn ...

  6. python3.4学习笔记(十八) pycharm 安装使用、注册码、显示行号和字体大小等常用设置

    python3.4学习笔记(十八) pycharm 安装使用.注册码.显示行号和字体大小等常用设置Download JetBrains Python IDE :: PyCharmhttp://www. ...

  7. python3.4学习笔记(十九) 同一台机器同时安装 python2.7 和 python3.4的解决方法

    python3.4学习笔记(十九) 同一台机器同时安装 python2.7 和 python3.4的解决方法 同一台机器同时安装 python2.7 和 python3.4不会冲突.安装在不同目录,然 ...

  8. python3.4学习笔记(十六) windows下面安装easy_install和pip教程

    python3.4学习笔记(十六) windows下面安装easy_install和pip教程 easy_install和pip都是用来下载安装Python一个公共资源库PyPI的相关资源包的 首先安 ...

  9. python3.4学习笔记(十五) 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)

    python3.4学习笔记(十五) 字符串操作(string替换.删除.截取.复制.连接.比较.查找.包含.大小写转换.分割等) python print 不换行(在后面加上,end=''),prin ...

随机推荐

  1. mybatis中获取参数

    1.${parameter}方式: parameter是数字时用:模糊查询%${parameter}%时用. 例:select * from account where userId = ${para ...

  2. 在django项目中使用django-ckeditor

    安装django-ckeditor pip install django-ckeditor 安装Pillow Pillow是python的一个图像处理库,django-ckeditor需要依赖该库.最 ...

  3. webdriver鼠标上下滑动

    有时候我们需要对窗口显示的页面上下滑动,以显示当前正在处理的位置,这就需要用到webdriver模拟鼠标上下滑动 package test20161201; import org.openqa.sel ...

  4. iOS 开发笔记-UILable/UIFont/UIButton常见设置

    UILabel的常见设置 @property(nonatomic,copy) NSString *text; 显示的文字 @property(nonatomic,retain) UIFont *fon ...

  5. dedecms开启报错

    php.ini里面设置display_errors = On 开启错误提示,error_reporting = E_ALL & ~E_NOTICE 设置错误等级.也可以在php文件中ini_s ...

  6. sql怎么批量替换字段里的字符串的

    方法一:varchar和nvarchar类型是支持replace,所以如果你的text不超过8000可以先转换成前面两种类型再使用replace 替换 text ntext 数据类型字段的语句 . 1 ...

  7. React组件,React和生命周期

    笔记,具体可以看看这个博客: https://segmentfault.com/a/1190000004168886?utm_source=tag-newest react 的jsx document ...

  8. “System.Data”中不存在类型或命名空间名称“TypedTableBase”

    错误 1 命名空间“System.Data”中不存在类型或命名空间名称“TypedTableBase”(是否缺少程序集引用?)  解决方案 因为是把强类型DataSet文件绑定报表的项目中出现的错误, ...

  9. linux常用命令:chmod 命令

    chmod命令用于改变linux系统文件或目录的访问权限.用它控制文件或目录的访问权限.该命令有两种用法.一种是包含字母和操作符表达式的文字设定法:另一种是包含数字的数字设定法. Linux系统中的每 ...

  10. Hive 大数据倾斜总结

    在做Shuffle阶段的优化过程中,遇 到了数据倾斜的问题,造成了对一些情况下优化效果不明显.主要是因为在Job完成后的所得到的Counters是整个Job的总和,优化是基于这些 Counters得出 ...