开发者

Weird behavior of std::vector

开发者 https://www.devze.com 2023-01-01 21:15 出处:网络
I have a class like this: class OBJ{...}; class A { public: vector<OBJ> v; A(int SZ){v.clear(); v.reserve(SZ);}

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 pr开发者_Python百科oblem 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,


I can guess - I would say that OBJ probably does not have a correctly implemented copy constructor and/or assignment operator and destructor.

0

精彩评论

暂无评论...
验证码 换一张
取 消