Please Help: CCArray containsObject() and indexOfObject() with CCObject Sub Classes

Guys, I am really having a hard time here with CCArray.

I’m storing a sub-class of CCObject and I need to be able to over-ride the equality check used by CCArray.

I have tried everything I could think of to override the correct method for CCArray.

My class is called STEShortestPathStep and I cannot get it to work with CCArray’s equality check.

Can anyone help? Please?

    bool operator==(STEShortestPathStep& rhs) const;
    bool operator==(const CCObject* pObject) const;
    virtual bool isEqual(const CCObject* pObject);

None of these will work, I was on the wrong path.

There is no way for CCArray to do this test — it is comparing pointers.

C++ has some very good reason to not allow overriding pointer equality checks.

What I did was create a sub-class of CCArray and added these methods:

unsigned int STEArray::indexOfObject2(CCObject* object)
{
    for(unsigned int i = 0; i < data->num; i++)
    {
        if( data->arr[i]->isEqual(object)) return i;
    }

    return CC_INVALID_INDEX;
}

bool STEArray::containsObject2(CCObject* object) {

    for(unsigned int i = 0; i < data->num; i++)
    {
        if( data->arr[i]->isEqual(object)) return true;
    }

    return false;
}