title: How to make a static map in c++?
body: <p>I am working on 2 files, lets take file1.cpp and file2.cpp.
  file1.cpp contains:</p>
  
  <pre><code>//File 1
  #include &lt;iostream&gt;
  #include &lt;map&gt;
  
  struct category {
      int id;
  };
  
  void fun();
  
  std::map&lt;char, category&gt; mymap1;
  static std::map&lt;char, category&gt; mymap;
  std::map&lt;char, category&gt;::iterator map_iter;
  std::map&lt;char, category&gt;::iterator map_iter1;
  
  int main ()
  {
  
      mymap1['a'] = {20};
      mymap1['b'] = {30};
      mymap1['c'] = {40};
  
      for(int i = 0;i &lt; 4; i++)
          fun();
  
      return 0;
  }
  
  //File 2
  #include&lt;file2.h&gt;
  void fun()
  {
       mymap = mymap1;
       map_iter = mymap.begin();
       for (map_iter1 = mymap1.begin(); map_iter1 != mymap1.end();++map_iter1)
       {
          map_iter-&gt;second.id = map_iter1-&gt;second.id - map_iter-&gt;second.id;
          std::cout&lt;&lt;map_iter1-&gt;second.id&lt;&lt;"  " &lt;&lt;map_iter-&gt;second.id;
          map_iter-&gt;second.id=map_iter1-&gt;second.id;
          ++map_iter;
       }
  
  }
  </code></pre>
  
  <p>I am trying to initialize mymap once when for loop run for the first time after that initialization should not happen as it happen in static variable.</p>
  
  <p>But this behaviour is not shown and each time mymap is getting initialize.</p>
  
  <p>I don't want the "id" getting initialize every time.</p>
  
  <p>How to work?</p>