开发者

std::bad_alloc but works in the end

开发者 https://www.devze.com 2023-03-20 16:55 出处:网络
I\'m developing an application on开发者_C百科 VS 2008 Express Edition on Debug mode. When instantiating a new pointer of a class I have created, I get a std::bad_alloc exception. Since it is in Debug

I'm developing an application on开发者_C百科 VS 2008 Express Edition on Debug mode. When instantiating a new pointer of a class I have created, I get a std::bad_alloc exception. Since it is in Debug mode, I click on 'break' in the window that has appeared and I try to resume the program by pressing on the 'play' button.

What happens next is rather unexpected: the program works as it should.

This error happens when I'm instantiating an array of Matrix objects (my class) using Matrix* vec = new Matrix[maxItr + 1]; (I've checked and maxItr is equal to five when the error is raised). This class has a few integers members and a pointer to a char. This pointer is not allocated in the default constructor (it is even set to 0), so I eliminated this as a cause of the error. (No extremely large blocks of memory are requested).

Does anyone have an insight on that?


Does the constructor of your class have a new in it? Or maybe a new that's buried inside another class, such as a vector? If so, maybe you're getting the allocation for the vector of objects but one or more of the objects contained within is malformed.

0

精彩评论

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

关注公众号