[英]Adding SEL_CallFuncO to a CCArray
I have the following code in my cocos2d-X application that is not compiling 我的cocos2d-X应用程序中有以下未编译的代码
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
. 不知道错误是什么,似乎基于实例化func1
和func2
使用了错误的callfunc_selector
。 I think you want to use callfuncO_selector
since it takes a CCObject*
. 我认为您想使用callfuncO_selector
因为它需要CCObject*
。
From CCObject.h
: 从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. 由于CCArray
仅用于CCObject
派生类, CCObject
您将需要遵循Vikas在注释中建议的内容,并使用std::vector
来容纳函数指针。 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));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.