模仿cocos2dx 风格用工厂方法,实现class A,不使用宏,

class A
{
        static A *create();
        bool init();
};

A* A::create()
{
        A *pRet=new A;
        if(pRet && pRet->init())
        {
            pRet->autoRelease();
        }
        else
        {
            delete pRet;
            pRet=NULL;
        }
        return pRet;
}

bool A::init()
{
 /*先初始化父类*/
 FATHER->init();
 return true;
}
原文地址:https://www.cnblogs.com/ttss/p/4060615.html