Weird behavior of std::vector
- by Nima
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,