I have the follow bare bones main program:
#include "asd.h"
int main() {
asd a;
a.input();
}
Below is the asd file which is a class file:
#include "asd.h"
int maxlength = 256;
vector<pair<int, int>> t;
void asd::input() {
for (int x = 0; x < 400; x++) {
tAdd(x);
}
}
void asd::tAdd(int x) {
if (t.size() == maxlength) {
vector<pair<int, int>>::iterator it = t.begin();
t.erase(it);
t.resize(maxlength);
}
//The function below gives me the error
t.push_back(make_pair(x, 0));
//
}
What is happening here? I am not operating with any pointers what so ever. I basically have a class called asd which holds a vector of a pair of ints as a data member. From my main program, I create an asd class object and call the input function. The input function just loops till 400 and calls the tAdd function. This function basically erases the first element of the vector and resizes it if it reaches max size. Then, there is a statement which pushes back a pair of ints. Here is the problem, it never actually gets to the point where it has to resize the vector. It always crashes at the 8th iteration and I know that it is the push back function that is causing it. Furthermore, the error is this:
double free or corruption(out)
Aborted (core dumped)