//Misc_Functions.cpp includes Global.h
vector<string> mill_pos_v;
vector<vector<string>> mill_pos_set_v;
//a0
mill_pos_v.push_back("b1");
mill_pos_v.push_back("c2");
mill_pos_set_v.push_back(mill_pos_v);
mill_pos_v.clear();
mill_pos_v.push_back("a3");
mill_pos_v.push_back("a6");
mill_pos_set_v.push_back(mill_pos_v);
mill_pos_v.clear();
mill_pos_v.push_back("d0");
mill_pos_v.push_back("g0");
mill_pos_set_v.push_back(mill_pos_v);
mill_pos_v.clear();
///the value does not get inserted into the map here
mill_positions["a0"]=mill_pos_set_v;
mill_pos_set_v.clear();
but nothing gets inserted into the map. Is there some other way I should do this? Or is there any other approach to do the same task?
I hope I've been able to make myself clear. Could someone please help me with this?
Globals are generally not a good idea to have around, but...are they properly declared extern everywhere except one cpp file? I'd except you'd get compiler errors if they weren't, but maybe not.
I do not think I can do away with globals in this case, since these data structures declared in Global.h has to be used by all functions and persisted across the game.
Or, do you think its a better I idea to pass the data structure to functions each time rather than making them global?
Yes, they have been declared as externs everywhere except in Misc_Functions.cpp
#include <vector>
#include <map>
#include <string>
#include <iostream>
usingnamespace std;
typedef vector<string> vs ;
typedef vector<vs> vvs ;
ostream& operator<<(ostream& os, const vvs& v) ;
ostream& operator<<(ostream& os, const map<string, vvs>&m) ;
int main()
{
map<string,vvs> mill_positions ;
vs mill_pos_v;
vvs mill_pos_set_v;
//a0
mill_pos_v.push_back("b1");
mill_pos_v.push_back("c2");
mill_pos_set_v.push_back(mill_pos_v);
mill_pos_v.clear();
mill_pos_v.push_back("a3");
mill_pos_v.push_back("a6");
mill_pos_set_v.push_back(mill_pos_v);
mill_pos_v.clear();
mill_pos_v.push_back("d0");
mill_pos_v.push_back("g0");
mill_pos_set_v.push_back(mill_pos_v);
mill_pos_v.clear();
///the value does not get inserted into the map here
mill_positions["a0"]=mill_pos_set_v;
mill_pos_set_v.clear();
cout << mill_positions << '\n' ;
}
ostream& operator<<(ostream& os, const map<string,vvs>& m)
{
for ( map<string,vvs>::const_iterator i = m.begin(); i!= m.end(); ++i )
os << i->first << ": " << i->second << '\n' ;
return os ;
}
ostream& operator<<(ostream& os, const vvs& v)
{
os << "{ " ;
for ( vvs::const_iterator i = v.begin() ; i != v.end() ; ++i )
{
os << "{" ;
for ( vs::const_iterator j = i->begin() ; j != i->end() ; ++j )
os << (j == i->begin()? "" : " ") << *j ;
os << "} " ;
}
return os << '}' ;
}
a0: { {b1 c2} {a3 a6} {d0 g0} }
Press any key to continue . . .
And, no, quickwatch still won't handle the iterator correctly. Too much indirection. I never used quickwatch, because it was just too useless. However a regular watch on the iterator does the job if you expand it in the watch window. In VS10, you can just hover over the expression in the source to get the result of a regular watch expression.