An episode is added here about the Cocos2d-x callback function. First, let's cocos the supported callback function macros, and their prototypes:
// 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::p laceholders::_1, # # __va_args__)#define cc_callback_2 (__selector__,__target__, ...) std::bind (&__selector__,__target__, std::p laceholders::_1, std::p laceholders::_2, # #__VA_ARGS__)#define cc_callback_3 (__selector__,__target_ _, ...) Std::bind (&__selector__,__target__, std::p laceholders::_1, std::p laceholders::_2, std::p laceholders::_3, # #__ VA_ARGS__)
Top right, above a total of 4 callback function macros. are implemented by c++11 new add bind (). The prototype is as follows:
Template <classclass... args> /** /bind (fn&& Fn, args&&return type ( 2 ) <classclass ... args> /** /bind (fn&& Fn, Args&& .... Args);
Use as follows, see 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::d ivides<double> my_divide;)DoubleMy_divide (DoubleXDoubleY) {returnx/y;}structMypair {Doubleb; DoubleMultiply () {returnA *b;}};intMain () {using namespacestd::p laceholders;//adds visibility of _1, _2, _3,...//binding functions:Auto fn_five = Std::bind (My_divide,Ten,2);//returns 10/2Std::cout << fn_five () <<'\ n';//5Auto Fn_half= Std::bind (My_divide,_1,2);//returns X/2Std::cout << Fn_half (Ten) <<'\ n';//5Auto Fn_invert= Std::bind (my_divide,_2,_1);//returns y/xStd::cout << Fn_invert (Ten,2) <<'\ n';//0.2Auto Fn_rounding= std::bind<int> (my_divide,_1,_2);//returns int (x/y)Std::cout << fn_rounding (Ten,3) <<'\ n';//3Mypair Ten_two {Ten,2}; //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.AStd::cout << bound_member_data () <<'\ n';//Ten return 0;}
About # #__VA_ARGS__见博客地址: http://www.cnblogs.com/zhujudah/archive/2012/03/22/2411240.html
As for __selector__ and __target__ should be Cocos custom things, I did not find the corresponding things in C99, there is time to control the definition of C11 (csnd happens today in the maintenance server, not downloaded).
The contents of the Placehoders namespace are as follows:
namespace placeholders{ extern/** / _1; extern /* * / _2 ; extern /* * / _3 ; // ...}
Cocos2d-x Study Notes (10) Cc_callback callback function related macro