Callback function pointer passing
The cc_callback_n macro series are defined from ccmacros. H, where n is 0 ~ 4, indicating the number of parameters of the wrapped callback function pointer.
Take the touch event as an example:
1 void test: initlistener () 2 {3 Auto listener = eventlistenertouchonebyone: Create (); 4 listener-> ontouchbegan = cc_callback_2 (test: ontouchbegan, this ); 5 listener-> ontouchmoved = cc_callback_2 (test: ontouchmoved, this); 6 listener-> ontouchended = cc_callback_2 (test: ontouchended, this ); 7 listener-> ontouchcancelled = cc_callback_2 (test: ontouchcancelled, this); 8}
Lambda expressions
Syntax format: [capture blocks] (parameters)-> return value type {subject}
The capture block is used to display the variables to be captured by the function in the specified closure. There are 6 expressions: [=] to capture all variables through value transfer; [&] indicates capturing all variables through reference transfer; [Var] indicates capturing the variable VAR through value instead of other variables; [& var] indicates capturing the VaR through reference, other variables are not captured. [=, & var] indicates that values are captured by default, and variables are captured by VAR reference. [&, VAR] indicates that values are captured by reference by default.
C11 characteristics used in cocos2d-x 3.x