title: How to overload a parentheses operator for both get and set?
body: <p>I am trying to overload a getter and setter using parentheses operator. When I try to use </p>
  
  <pre><code>double&amp; my_vector::operator()(size_t index){
      return array[index]
  }
  </code></pre>
  
  <p>This single operator overloading <strong>works</strong> for both the case:</p>
  
  <p>eg: <code>my_vector(1) = 4.01;</code> &amp; <code>double x = my_vector(1);</code></p>
  
  <p>But now I want to make getter as <code>const</code> and setter and <code>non-const</code> since I will be using const getter in another const function. I do </p>
  
  <p>getter as  <code>double&amp; my_vector::operator()(size_t index) const;</code> </p>
  
  <p>setter as <code>double&amp; my_vector::operator()(size_t index);</code> </p>
  
  <p>I get 
  Error: <strong>functions that differ only in their return type cannot be overloaded.</strong></p>
  
  <p>I think I know what the error is talking about but I am not sure how to rectify it. </p>