global std::map variable in c++
<p>I need to use a std::map variable across several files. Most of the example says, I need to declare it as extern on .h file and initialize on any one of the .cpp file.  But I don't see updated value on the std::map variable.</p>

<p>Example: 
Config.h</p>

<pre><code>struct Action_Element {
    std::string algo_func_name;
    uint32_t opEventUid;
};

typedef std::map&lt;int, Action_Element&gt; EnActionList;
typedef std::map&lt;int, Action_Element&gt; ExActionList;
typedef std::map&lt;size_t, string&gt; CondExpStrList;

struct Transition_Elements {
    uint32_t              DesStateUid;
    uint32_t              TransCounterID;
    ExActionList          ExitActionList;
};

typedef std::map&lt;uint32_t, Transition_Elements&gt; TransitionList;

struct State_Element {
    bool              isTransitionCondAvailable;
    EnActionList      EntryActionList;
    TransitionList    TransitionList;
};

typedef std::map&lt;uint32_t , State_Element&gt; StateList;
extern StateList global_stateList;     // global state list
</code></pre>

<p>file1.cpp</p>

<pre><code>#include "Config.h"

file1::file1()
{
   State_Element  file1StateElement;
   global_statList.insert(make_pair(1,file1StateElement);
}
</code></pre>

<p>file3.cpp</p>

<pre><code>#include "Config.h"

file3::file3()
{
   State_Element  file3StateElement;
   global_statList.insert(make_pair(3,file3StateElement);
}
</code></pre>

<p>file2.cpp</p>

<pre><code>#include "Config.h"

file2::file2()
{
   State_Element  file2StateElement;
   global_statList.insert(make_pair(2,file2StateElement);
}
</code></pre>

<p>Let us not consider whats inside each State_Element and how it is initialized.</p>

<p>main.cpp</p>

<pre><code>#include "Config.h"
StateList global_stateList;

int main(void) {

global_stateList.clear();
file1 *f1 = new file1();
file2 *f2 = new file2();
file3 *f3 = new file3();

StateList::const_iter iter = global_stateList.begin();
if(iter != global_stateList.end())
{
   printf("\n size of globalstateList : %d", global_stateList.size());
}

while(1);

}
</code></pre>