Accessing custom class properties

Accessing custom class properties
0.0 0


Hi everyone,
Perhaps this is a stupid question, (and I hope so, thus it would mean that there is an easy solution), I had troubles when trying to access properties from custom made classes. I attach an example code with CCa class initializated and added inside CCb class.

Initially, my problem was that CCa class parameters where empty inside CCa::doAction, though memory pointer where the same than these inside CCb.
I “solved” these issue using retain and release at CCa creation and destruction.

But - there is always a “but” - now it crashes giving a signal SIGABRT exception, sometimes when a point is added (inside CCb::init()) and always when any thing is added inside results arra ).
<pre>void CCObject::retain
I’ve searched through forums, and seen that this exception appears on some other situations, but no solution given on such suits me.
I will appreciate any orientation if this “solution” is not correct, or any walkarround to solve any code mistake that I - with no doubt - have done:
file “CCa.h”
#include “cocos2d.h”
using namespace cocos2d;
class CCa : public CCMenuItem {
const char **name;
CCArray **values;
CCArray ***results;
virtual ~CCa;
virtual bool init;
void addPoint;
void doAction;
file “CCa.cpp”
<pre>#include “CCa.h”
CCa::CCa {
this~~>*positions = CCArray::create;
this~~>*values = CCArray::create;
this~~>*results= CCArray::create;
this~~>*name = “”;
this~~>*value = 0;
CCa::~CCa {
if {
if {
if {
if {
this~~>*name = NULL;
bool CCa::init;
if ) {
return false;
if {
this~~>*name = name;
return true;
void CCa::addPoint {
this~~>*values~~>addObjectnew int);
void CCa::doAction {
const char **aName = *this~~>name;
//Assuming there is, at least, one element inside
points and values
aPoint = *this~~>positions~~>objectAtIndex;
aValue =**this~~>*values~~>objectAtIndex;
CCSprite **anythingWouldDoTheSame = CCSprite::create;
this~~>results~~>addObjectanythingWouldDoTheSame); //whenresults has been retained and throws CCAssert exception commented above
file “CCb.h”
<pre>#include “cocos2d.h”
using namespace cocos2d;
class CCa : public CCScene {
virtual bool init;
static CCScene* scene;
file “CCb.cpp”
<pre>#include “CCb.h”
//omitting static CCScene* scene
CCb::init {
CCa **object = new CCa();
_object~~>init, “object Name”);
_object~~>addPosition(ccp(23, 45), 1);

Thanks in advance! :)



  1. You don’t need to init() arrays, they’re already inited when created with static create() method.
  2. You need to retain() (or CC_SAFE_RETAIN) arrays you create with create() to prevent them from being autoreleased.
  3. CC_SAFE_DELETE_ARRAY is for deallocating dynamically allocated C arrays, not for CCArray! You just need to release() your arrays here, or CC_SAFE_RELEASE.
  4. You can’t do release() on const char**. You need to do nothing if it’s string literal, or need to do delete if it’s dynamically allocated. Better use std::string or CCString.
  5. this~~>_values~~>addObjectnew int); You can’t cast int** to CCObject*. Use std::vector or a custom CCObject wrapper for int.