I have distilled the essence of my problem! example:
struct arrayInside {
int* arr;
arrayInside(int n) {
arr = new int[n];
}
~arrayInside() {
delete arr;
}
};
void main() {
std::vector<arrayInside> vec;
for (int i = 10; i < 20; i++) {
vec.push_back(arrayInside(i));
}
}
this results in a crash because upon each push_back into the vector, the destructor is called on something and in the end, it ends up trying to delete addresses don't in fact contain the array created in the constructor.
I could circumvent this by instead storing pointers of arrayInside but this is about convenience, I don't want to have to loop through the vector again to delete every item. How can I make the arrayInside class vector proof?