I have the following code in my cocos2d-X application that is not compiling
SEL_CallFuncO func1 =callfunc_selector(BPBasketLayer::addSingleNumberBasket);
SEL_CallFuncO func2 =callfunc_selector(BPBasketLayer::addSpawnPowerUp);
CCArray *arr=CCArray::create();
arr->addObject(func1);
arr->addObject(func2);
Now this is giving me an error ? What am i doing wrong ?
Kind Regards
Without knowing what the error is, it looks like you're using the wrong callfunc_selector
based on how you are instantiating func1
and func2
. I think you want to use callfuncO_selector
since it takes a CCObject*
.
From CCObject.h
:
typedef void (CCObject::*SEL_CallFuncO)(CCObject*);
#define callfuncO_selector(_SELECTOR) (SEL_CallFuncO)(&_SELECTOR)
Edit:
You will need to follow what Vikas suggested in the comments and use a std::vector
to house the function pointers since CCArray
is for CCObject
derived classes only. So something like this:
std::vector <SEL_CallFuncO> func_ptr_array;
func_ptr_array.push_back(callfuncO_selector(BPBasketLayer::addSingleNumberBasket));
func_ptr_array.push_back(callfuncO_selector(BPBasketLayer::addSpawnPowerUp));