Search code examples
c++iospointerscocos2d-x

In CCCallFuncND we pass pointers. Is it a good practice to pass pointer of local scope


In CCCallFuncND we pass pointers . Is it a good practice to pass pointer of local scope(i.e. pointers declared and allocated in a member) from another method.

The method is like:-

CCCallFuncND * CCCallFuncND::create(CCObject* pSelectorTarget, SEL_CallFuncND selector,    void* d)
{
    CCCallFuncND* pRet = new CCCallFuncND();

    if (pRet && pRet->initWithTarget(pSelectorTarget, selector, d))
    {
        pRet->autorelease();
        return pRet;
    }

    CC_SAFE_DELETE(pRet);
    return NULL;
}

Solution

  • It is not a good practice. You can pass, but you can't use it if you didn't run the CCCallFuncND immediately. if you put it in to a CCSequence and run it later, the void* will pointing to some invalid address.