OSX 10.7, XCode 4.
I have a small problem: I need to push back a 2D vector<vector<float>> in to a 3D Vector, after a process of selection. It throws the EXC_BAD_ACCESS error in the push_back function in the stl::vector template. It seems like it should be simple (I’ve worked with complex data structures many times before), I’ve tried a varying amount of ideas but to no avail. Everything else works and outputs the values that I’d expect to the command line. I’m sure its code blindness, and some easy rep to pick up.
I ask only because I believe that my syntax is correct, but at compile time I have issues. Heres some sample code:
Implementation:
for(int i=0;i<fdisVec.size();i++){
int j;
if(fdisVec[i] < fdisVec2[i]){
j = 0;
}
else if(fdisVec2[i] < fdisVec[i]){
j = 1;
}
clusters[j].push_back(allMfccs[i]);
}
and my .h has the objects declared as such (public members of class):
vector< vector <float> > allMfccs;
vector< vector < vector <float> > > clusters;
In case it helps, fdisVec and fdisVec2 are also 2d Vectors, however, the “if else” statement responds how I want it to – I highly doubt it would be something to do with that.
What if fdisVec[i] == fdisVec2[i] ?
In this case, j is left uninitialized (garbage), and sometimes the value is not a valid index for your clusters vector.