CIwArray push_back throws error

228 views Asked by At

I am trying a contact list kinda app and want to hold this data in a dynamic array. CIwArray was the choice of mine since I've used that before. However it's working strange now, probably due to Marmalade 7.4.2 since I've just updated.

My declaration in header file is like this -

CIwArray<ContactData*>  m_ContactList;

And I push back data like this -

ContactData* contact = new ContactData;
m_ContactList.push_back(contact);

On the push back call, I am constantly getting Access Violation error and when I break it I get struct at NULL for m_ContactList while contact object is working fine. I do not understand where I am wrong. I tried pushing back an integer too by changing the generic type as int, but I get same error. The IwAssert that's getting hit is in IwArray.h at line 650 -

int push_back(X const & x)
    {
        // This IwAssertion fires if you've passed a reference to a controlled
        //  object (which might become invalid if the memory buffer moves before
        //  we dereference it!)
        // I don't think this is an unreasonable requirement, since the
        //  alternative would be to create a copy of the object on the stack.
        // If you need to do this behaviour, code like:
        //  {
        //      CIwArray< ThingZ > array_z;
        //      // fill up array_z with something or other here before trying:
        //      array_z.push_back( ThingZ( array_z[0] ) );
        //  }
        //  should work. (Although it's not terribly elegant.)
        IwAssert(CORE, !(&x>=p && &x<p+max_p));  //THAT"S WHAT HITTING EVERY TIME

        reserve(num_p+1);
        IwAssert(CORE, num_p < max_p);
        new (p+num_p) X(x);
        return num_p++;
    }

I don't understand what the comment is trying to say. Can anyone explain?
Thanks

1

There are 1 answers

0
0xC0DED00D On BEST ANSWER

The answer to this question came from another SO Question. The problem was I was not creating an instance of the class and the code was getting called on a NULL object.
More Details