Cocos Advanced Tutorials (5) Tips for using the Cc_callback_x series

Source: Internet
Author: User

Cc_callback_1,cc_callback_2,cc_callback_3

These are the Std::bind macros, the digital three-in-one mainly represents the number of positions to occupy, but also the number of parameters passed in the future.

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__)

The corresponding std::bind has several placeholders for std::p laceholders::_1,std::p laceholders::_2,std::p laceholders::_3, and so on, these placeholders are the ones that we're calling specific functions (&__ SELECTOR__) need to pass the parameters, White is to tell us the target &__selector__ in front of the number of parameters need to be passed, cc_callback_2 (__selector__,__target__, ...) Here's the ... It is also possible to pass in parameters, but this parameter cannot replace the placeholder parameter, and the placeholder parameter can only be passed in the call, where the parameter is the value of the parameter after the position parameter is assigned a default value.

Examples Show

Helloworld::sayname (name1, name2, Name3, Name4, Name5) {

}

Cc_callback_3 (Self::sayname, Self, "Xiao Ming", "Xiao Li") This sentence is Std::bind (&__selector__,__target__, std::p laceholders::_1, std::p laceholders::_2, std::p laceholders::_3, "Xiao Ming", "Xiao Li")

Assume

Auto Delegatefucname = Std::bind (&__selector__,__target__, std::p laceholders::_1, std::p laceholders::_2, std:: Placeholders::_3, "Xiao Ming", "Xiao Li")

Delegatefucname (...) This time ... Is the value of the 3 placeholders to be passed, Delegatefucname ("Snow", "Small Wind", "Floret")

The end result is the placeholder pass parameter ("Snow", "Small Wind", "Floret") +cc_callback_3 subsequent parameters ("Xiao Ming", "Xiao Li") complete the parameters of the objective function sayname

Cocos Advanced Tutorials (5) Tips for using the Cc_callback_x series

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.