【发布时间】:2014-11-13 07:32:02
【问题描述】:
我正在尝试一个联系人列表应用程序,并希望将这些数据保存在动态数组中。 CIwArray 是我的选择,因为我以前使用过它。但是现在它的工作很奇怪,可能是因为我刚刚更新了 Marmalade 7.4.2。
我在头文件中的声明是这样的——
CIwArray<ContactData*> m_ContactList;
然后我像这样推回数据 -
ContactData* contact = new ContactData;
m_ContactList.push_back(contact);
在回推调用中,我不断收到访问冲突错误,当我打破它时,我在联系人对象工作正常时得到 m_ContactList 的 NULL 结构。我不明白我错在哪里。我也尝试通过将泛型类型更改为 int 来推回一个整数,但我得到了同样的错误。受到打击的 IwAssert 位于第 650 行的 IwArray.h -
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++;
}
我不明白评论想说什么。谁能解释一下?
谢谢
【问题讨论】: