I have a class Bar
, its constructor initializes a std::vector
of type Foo
(another class).
Bar.cpp
Bar::Bar(int n) {
for(int i = 0; i < n; i++) {
Foo foo;
foo.somefunction(i);
vec.push_back(foo) //this should insert foo into the vector
}
}
Bar.h
class Foo;
class Bar {
std::vector<Foo> vec;
};
When I debug, the first iteration of the construction works fine. foo
is created, foo.somefunction()
is run fine, and foo
is pushed into vec
.
The second interation seems to work fine as well, but the program crashes when it goes back to start the third iteration.
I get _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
error and HEAP CORRUPTION DETECTED
.
Foo
is a class that contains an dynamically created array, nothing special.
Something like this:
Foo::Foo() {
solution = new float[size];
// some function that initializes the elements of solution
}
and a regular destructor ~Foo() {delete [] solution;}
. I don't think the problem comes from Foo
.