Using CREATE_FUNC

Hello all,

Can anyone explain me why do we need to use CREATE_FUNC ? I saw it in the HelloWorld samples and don’t understand it clearly. Please, tell me more detail. Thanks.

this is simply macro

/**
 * define a create function for a specific type, such as CCLayer
 * @__TYPE__ class type to add create(), such as CCLayer
 */
#define CREATE_FUNC(__TYPE__) \
static __TYPE__* create() \
{ \
    __TYPE__ *pRet = new __TYPE__(); \
    if (pRet && pRet->init()) \
    { \
        pRet->autorelease(); \
        return pRet; \
    } \
    else \
    { \
        delete pRet; \
        pRet = NULL; \
        return NULL; \
    } \
}

So simply you have call for init() and autorelease for free

@gelldur Do I ALWAYS have to use it?

It’s just a syntactic sugar, so you don’t have to use it.