thank you snk_kid.
I knew there is no way to hide those variables. So it is considered to be rather poor design putting the stuff into a namespace without a class declaration as all variables become global.
Ok. I've put all into a class but another problem arises. I dont know what that is. I've been staring at it for soo long.
When I put the implementation of Open() function in implementation file Foo.cpp then I get linkink error when I use STL map:
#ifndef _FOO_H_ // we are in Foo.h file#define _FOO_H_#include <vector>#include <map>using namespace std;______________________________________namespace MY{ typedef vector<string> TestNames; typedef map<string, TestNames> TestMap; class CFoo { public: static void Open(); static void Close(); private: static TestMap map; static TestNames names; };};#endif
// we are in Foo.cpp implementation file now. THIS IS WHERE THE PROBLEM IS.
#include "stdafx.h"#include "Foo.h"using namespace MY;void Foo::Open(){ TestNames names; string str = "Name_Peter"; names.push_back(str); str = "Name_Andrew"; names.push_back(str); string key = "key_1"; map[key] = names; //<-- IT FAILS HERE. 1 error. When I comment it then the error disappears}
This generates error: error LNK2001: unresolved external symbol "private: static class std::map,class std::allocator >,class std::vector,class std::allocator >,class std::allocator,class std::allocator > > >,struct std::less,class std::allocator > >,class std::allocatorair,class std::allocator > const ,class std::vector,class std::allocator >,class std::allocator,class std::allocator > > > > > > TMMAP::CTexMeshMatch::Mesh_map" (?Mesh_map@CTexMeshMatch@TMMAP@@0V?$map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@2@U?$less@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@2@@std@@@2@@std@@A)
I just cant get rid of it. Please help!
[edited by - papa on May 31, 2004 10:11:12 AM]