title: C++ overload map [ ] operator
body: <p>I have 2 overloaded operator declaration that I need help understanding.</p>
  
  <pre><code>template&lt;class KEY, class T&gt;
  const T&amp; Map&lt;KEY, T&gt;::operator [](const KEY&amp; key) const { }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>template&lt;class KEY, class T&gt;
  T&amp; Map&lt;KEY, T&gt;::operator [](const KEY&amp; key) { }
  </code></pre>
  
  <p>the first <code>[]</code> is used to access the value/return value, i.e <code>std::cout&lt;&lt;m["x"]&lt;&lt;std::endl;</code></p>
  
  <p>the second <code>[]</code> is for assignment, i.e <code>m["x"] = 1;</code></p>
  
  <p>The question I have pertains to the 2nd <code>[]</code>. If I were to do <code>m["z"] = 10</code>, how does <code>10</code> get stored as the value associated with key <code>z</code>? Looking at the function declaration, I only see the key, not value. </p>
  
  <p>I tried doing <code>m_value = T();</code>, but I'm not sure what T() is.</p>
  
  <p>Thank you</p>