Problem with push_back(pair<int,float>)

I'm working on an implementation of a genetic algorithm to find good solutions for a problem. This requires me to store a vector of pairs, where each pair consists of an int value ((-1) or (1)) and a float score ([0..1]).

This is what I use to define the variables and save the data:
1
2
3
4
5
6
7
8
9
10
11
12
13
//// these are defined in the class Track ////
vector<pair<int,float>> _path;	// moves and chances from _initStore. (-1)=Left, (1)=Right.
float _score;			// Buy % of the track '_path'
//////////

//// these commands are executed in a Track member function: void Track::calcScore(Robot* r, vector<int> path) ////
int move;				// Current randomized move
pair<int,float> curMove;		// Temp for current move/score

_path.reserve((leftMoves+rightMoves));	// Reserve enough space in the path vector _path
curMove=make_pair(move,_score); 	// move=(-1) or (1). _score=[0..1]
_path.push_back(curMove);
////////// 


Please note that path is a vector<int> which belongs to the function calcScore, while _path is a member of instances of the class Track.

Using the debugger, after the _path.reserve command the debugger shows _path to be size=0, capacity=8.
After the curMove=... command curMove does contain the right arguments - for example (1,0.8999).
However, after the push_back command, the debugger shows _path as having size=2 and capacity=8, with the _path[0]=1 and _path[1]=0.8999. Both types are shown as int in the Type column.

Why does this happen?
Can't a vector store a pair?
Last edited on by admin
What debugger are you using? On VC++ it works fine for me.
Weird. for debugging, I added this line following _path.push_back(curMove):

 
cout<<"curMove.second="<<curMove.second<<", _path[moveI].second="<<_path[moveI].second<<endl;


I wanted to see if the debugger was just displaying the information wrong, or was it actually storing wrong types. To use cout, I added #include <iostream> (using namespace std; was already in the code), and Voila! it worked.

This is the only thing which was changed in the code. I am not sure what exactly caused the problem and what solved it (especially considering that removing <iostream> did not bring the problem back), but I'll leave this investigation for other times.

p.s.
I'm using visual c++ v10.0.30319.1 and its debugger.

in any case,
thanks for your time
Last edited on by admin
Topic archived. No new replies allowed.