单例cocos2dx

来源:互联网 发布:linux改变用户权限 编辑:程序博客网 时间:2024/06/07 06:28
.h

public:
   staticRoleCardController * getInstance();


.m
//1.实现单例方法,首先我们要有一个静态对象
staticRoleCardController*roleCardController = nullptr;

//我们来实现一个单例的方法
RoleCardController*RoleCardController::getInstance()
{
   if(roleCardController==nullptr) {
       //2.如果发现是空的,我们就来new一个
       roleCardController= new(std::nothrow)RoleCardController();
       //3.然后让它执行初始化方法
       roleCardController-> init();
    }
   returnroleCardController;
}

原创粉丝点击