Accessing custom class properties

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
{
CCAssert;
++m_uReference;
}</pre>
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”
<pre>
#include “cocos2d.h”
using namespace cocos2d;
class CCa : public CCMenuItem {
public:
const char **name;
int
value;
CCArray
**positions;
CCArray **values;
CCArray ***results;
CCa;
virtual ~CCa;
virtual bool init;
void addPoint;
void doAction;
};</pre>
file “CCa.cpp”
<pre>#include “CCa.h”
CCa::CCa {
this~~>*positions = CCArray::create;
this~~>*positions~~>init;
this~~>*values = CCArray::create;
this~~>*values~~>init;
this~~>*results= CCArray::create;
this~~>*results~~>init;
this~~>*name = “”;
this~~>*value = 0;
}
CCa::~CCa {
if {
CC_SAFE_DELETE_ARRAY;
}
if {
CC_SAFE_DELETE_ARRAY;
}
if {
CC_SAFE_DELETE_ARRAY;
}
if {
this~~>*name~~>release;
this~~>*name = NULL;
}
}
bool CCa::init;
if ) {
return false;
}
if {
this~~>*name = name;
}
return true;
}
void CCa::addPoint {
this~~>*points~~>addObject&aPoint);
this~~>*values~~>addObjectnew int);
}
void CCa::doAction {
const char **aName = *this~~>name;
//Assuming there is, at least, one element inside
points and values
CCPoint
aPoint = *this~~>positions~~>objectAtIndex;
int
aValue =**this~~>*values~~>objectAtIndex;
CCSprite **anythingWouldDoTheSame = CCSprite::create;
this~~>results~~>addObjectanythingWouldDoTheSame); //whenresults has been retained and throws CCAssert exception commented above
}</pre>
file “CCb.h”
<pre>#include “cocos2d.h”
using namespace cocos2d;
class CCa : public CCScene {
public:
virtual bool init;
static CCScene* scene;
CREATE_FUNC;
};</pre>
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! :)

CCa.cpp:

  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.