zoukankan      html  css  js  c++  java
  • std::function 测试

    #ifndef __HELLOWORLD_SCENE_H__
    #define __HELLOWORLD_SCENE_H__
    #include "cocos2d.h"
    
    typedef std::function<void(int code)> TestCallback;
    #define CALLBACK_1(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, ##__VA_ARGS__)
    
    class HelloWorld : public cocos2d::Layer{
    public:
        static cocos2d::Scene* createScene();
        virtual bool init();
        CREATE_FUNC(HelloWorld);
    private:
        void handler(int code);
        void testCallback(TestCallback callback);
    };
    
    #endif // __HELLOWORLD_SCENE_H__
    #include "HelloWorldScene.h"
    USING_NS_CC;
    
    Scene* HelloWorld::createScene(){
        auto scene = Scene::create();
        auto layer = HelloWorld::create();
        scene->addChild(layer);
        return scene;
    }
    
    bool HelloWorld::init(){
        if ( !Layer::init() )return false;
        testCallback(CALLBACK_1(HelloWorld::handler,this));
        return true;
    }
    
    void HelloWorld::handler(int code){
        log("handler:%i",code);
    }
    
    void HelloWorld::testCallback(TestCallback callback){
        callback(105);
    }

    //输出:105

  • 相关阅读:
    [bzoj3123] [Sdoi2013]森林
    [bzoj2173] 整数的lqp拆分
    Linux
    使用高德地图API
    EF具体用在什么类型的项目上
    出现Data Tools 与VS 不兼容问题
    Entity FramWork
    Entity
    Entity
    BASH
  • 原文地址:https://www.cnblogs.com/kingBook/p/5530181.html
Copyright © 2011-2022 走看看