Weird behavior of std::vector

Posted by Nima on Stack Overflow See other posts from Stack Overflow or by Nima
Published on 2010-05-27T19:21:17Z Indexed on 2010/05/28 0:41 UTC
Read the original article Hit count: 350

I have a class like this:

class OBJ{...};

class A
{
   public:
   vector<OBJ> v;
   A(int SZ){v.clear(); v.reserve(SZ);}
};

A *a = new A(123);
OBJ something;
a->v.push_back(something);

This is a simplified version of my code. The problem is in debug mode it works perfect. But in release mode it crashes at "push_back" line. (with all optimization flags OFF) I debugged it in release mode and the problem is in the constructor of A. the size of the vector is something really big with dummy values and when I clear it, it doesn't change...

Do you know why?

Thanks,

© Stack Overflow or respective owner

Related posts about stdvector

Related posts about visual-c++-2008