title: Why are there two definitions of operator[]?
body: <p>I'm currently working on material from my data structures class, which involves an exercise where we attempt to define a class mimicking a vector so we can get an understanding of what's going on underneath the hood. Everything made sense until I realized that there are two definitions for<code>operator[]</code>. In context:</p>
  
  <pre><code>typedef unsigned int size_type;
  T&amp; operator[] (size_type i) { return m_data[i]; }
  const T&amp; operator[] (size_type i) const { return m_data[i]; }
  </code></pre>
  
  <p>First question: why is it necessary to have two definitions of <code>operator[]</code>?</p>
  
  <p>Second question: why doesn't this throw a multiple definitions error?</p>
  
  <p>Sorry if anything is vague or seems obvious. I'm new to C++, my only other experience being in Java. Thanks!</p>