I found some problems for std::list
when I'm doing some iPhone development under Xcode. Here is the code:
///////////// interface //////////////
class CObj
{
public:
int value;
};
typedef std::list<CObj*> ObjList;
@interface testAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
ObjList m_objs;
}
//////////// implementation /////////
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
for (int i = 0; i< 10; i++ )
{
CObj* obj = new CObj;
obj->value = i;
m_objs.push_back(obj);
}
NSLog(@"%d objects",m_objs.size() );
ObjList::iterator it = m_objs.begin();
while (it != m_objs.end())
{
CObj* obj = *it;
if ( obj->value == 3 )
it = m_objs.erase(it);
else
it++;
}
NSLog(@"%d objects",m_objs.size() );
}
The application simply crashes at m_objs.push_back. But if I change the std::list
to std::vector
, everything's fine. Any idea? Thanks