Reputation: 1537
I have an error I couldn't figure where it occues on the following:
I'm acutally using a map with vectors in it:
map<vector<string> , vector<string> > parameterMap;
because I need a few of them (how many is decided on runtime) I put them into a list (vector):
vector declaration on head of method:
vector<map<vector<string> , vector<string> > > listedParameterMap;
insertion of a map into the vector:
listedParameterMap.insert(listedParameterMap.end(), 1, parameterMap);
This procedure works fine on the first time. The second time (map is filled correctly) it down't work.
I noticed a thing: I give out the size of the map:
cout << "listedParameterMap " << listedParameterMap.size();
it shown size is 2 after the second time, the watch says it still 1.
It also shows me wired content:
Screenshot:
Last
should contain something looking like First
The second map which is inserted is defently filled correctly.
Same for the vectors: part1_input
and part2_output
Code:
for (unsigned int index = 0; index < part1_input.size(); index++) {
map<vector<string> , vector<string> > parameterMap;
parameterMap.insert
(pair<vector<string> , vector<string> > (part1_input[index], part2_output[index]));
listedParameterMap.insert(listedParameterMap.end(), 1, parameterMap);
cout << "listedParameterMap " << listedParameterMap.size();
}
I really would appreciate any ideas why this happens...
EDIT:
"Solution" was printing the stuff out. The watch-window isn't displaying the correct values. That means my Problem is caused somewhere else. But this here is anwsered. Thanks to anyone how tried to help me!
Upvotes: 0
Views: 533
Reputation: 31445
I would like to see a test where you output something from your collections to see if you are seeing what you think you should see. Actually why not write a proper unit test?
You are passing a lot of collections around by value. This can be quite expensive, but in addition, you may be updating something that is a copy of what you think you are actually updating, and then not seeing the results in the original.
I would not pay too much attention to values in Visual Studio's "watch" window, particularly if you are running an optimised build.
Upvotes: 1