I can't use the addObject() of CCArray!

I can't use the addObject() of CCArray!
0.0 0


i have tried hundreds of times!so simple code can’t correctly run,who can tell me why?

CCArray * arr=CCArray::array();
CCSprite * sprite=CCSprite::create(“001.png”);
arr~~>addobject;//an assertion error occured here
i added arr~~>retain() but the error still occured.if there is no array,i couldn’t continue


write this after CCArray create


thanks,it’s ok now!
maybe i am a bit thoughtless.


I am using COCOS 2dx 3.1

I declare

cocos2d::CCArray *_targets;
cocos2d::CCArray *_projectiles;

in header file

and i use

_targets = new CCArray;
_projectiles = new CCArray;


in init() funtion in cpp file

still got error on


in addtarget() funtion in same cpp file


Problem Solved

I just change


targets = new CCArray;
projectiles = new CCArray;


_targets = CCArray::create();
_projectiles = CCArray::create();