In a part of my code, I have
a = cache[k1][k2][k3][k4];
cout << "DEBUG: " << a << " " << cache[k1][k2][k3][k4] << endl;
And my cout has the following output:
DEBUG: 38 38
DEBUG: 3 3
DEBUG: 37 37
DEBUG: 4 35 <- the problem
I don’t understand what in the world is going on.
a,k1,k2,k3,k4 are integers and cache is a
vector<vector<vector<vector<int> > > >
The only way this could occur is if one of the indexes is out of bounds and so you’re accessing memory that’s outside of the vectors. The vector member function
atworks just like a subscript operator except that it does bounds checking, use it to detect this error.