title: Addresses of variables in constructor when an object is being inserted in a std::map
body: <p>I really don't understand the outcome of this code:</p>
  
  <pre><code>struct exampleClass
  {
      double a = 12.1;
      std::map&lt;int, double*&gt; innerMap;
  
      exampleClass()
      {
          std::cout &lt;&lt; "ADR of  variable a in constructor = " &lt;&lt; &amp;a &lt;&lt; std::endl;
          std::cout &lt;&lt; "ADR of this in constructor = " &lt;&lt; this &lt;&lt; std::endl;
          innerMap.emplace(4,&amp;a);
      }
  };
  
  
  int main(){
      std::map&lt;int, exampleClass&gt; map;
      map.insert(std::make_pair(4, exampleClass{}));
  
  
      for (auto&amp; it : map)
      {
          std::cout &lt;&lt; "ADR of a = " &lt;&lt; &amp;(it.second.a) &lt;&lt; std::endl;
          std::cout &lt;&lt; "Content of a = " &lt;&lt; it.second.a &lt;&lt; std::endl;
          std::cout &lt;&lt; it.second.innerMap.find(4)-&gt;second &lt;&lt; std::endl;
          std::cout &lt;&lt; *(it.second.innerMap.find(4)-&gt;second); //the output is wrong
      }
  }
  </code></pre>
  
  <p>The outcome is:</p>
  
  <pre>
  ADR of  variable a in constructor = 0x7ffee080b500 
  
  ADR of this in constructor = 0x7ffee080b500
  
  ADR of a = 0x559ddb2c42e8
  
  Content of a = 12.1
  
  0x7ffee080b500
  
  6.95312e-310
  </pre>
  
  <p>I do not understand why the addresses in the <code>for</code> loop differ from the addresses in the constructor. Also the "constructor address" is used for inserting in the <code>innerMap</code>, which causes a bug.</p>
  
  <p>Can someone explain this to me?</p>
  
  <p>What confuses me additionally is that the following works as expected:</p>
  
  <pre><code>exampleClass abc{};
  std::cout &lt;&lt; "ADR of a = " &lt;&lt; &amp;(abc.a)&lt;&lt; std::endl;
  std::cout &lt;&lt; *(abc.innerMap.find(4)-&gt;second) &lt;&lt; std::endl;
  </code></pre>