C++ 11 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, ##VA_ARGS)

… 和##VA_ARGS 是什么意思?

看这个,这篇讲得很详细
http://www.cocoachina.com/bbs/read.php?tid-198291-keyword-%23%23\_\_VA\_ARGS\_\_.html

… 和##__VA_ARGS__想详细了解的话,可以看下这个
http://blog.sina.com.cn/s/blog_af95b18b01018o9y.html

— Begin quote from ____

引用第2楼abc88798于2015-01-20 15:35发表的 :
… 和##__VA_ARGS__想详细了解的话,可以看下这个
http://blog.sina.com.cn/s/blog_af95b18b01018o9y.html http://www.cocoachina.com/bbs/job.php?action=topost&tid=282417&pid=1225535

— End quote

auto menuItem = MenuItemLabel::create(label, CC_CALLBACK_1(TestController::menuCallback, this));

为什么要传这个this ? 是TestController 的对象 ? 调用时 this-> menuCallback。

如果是这样的话,如果这是一个全局函数呢?

也就是说std::bind 怎么知道这是全局函数还是成员函数??

http://blog.csdn.net/qq575787460/article/details/8531397
http://blog.csdn.net/fjb2080/article/details/7527715

基本懂了 std:: bind 就是为bind 非静态函数而生了,当然也可以bind 全局或静态函数, 而std::function 只能绑定全局或静态函数 。

简单的可以这么说 。std::function是函数类型,确切的说。

成员函数可被看做是带有额外参数的自由函数:
struct X {
int foo(int);
};

    // 所谓的额外参数,
    // 就是成员函数默认的第一个参数,
    // 也就是指向调用成员函数的对象的this指针

this 是必须要绑,而且只能用bind 绑定

http://www.cnblogs.com/slysky/p/3822640.html

说的很好了 。 谢谢版主的支持。 基本搞明白了