title: Overload class function operator twice as setter and getter
body: <p>I have a class and i want to overload the fuction-call operator. But since the C++ standard forbids declaring two similar methods which only differ in return type, i get the compile error C2556. I want to use the functions as getter and setter methods. I know i can achieve this by creating a <code>get</code> and a <code>set</code> function. So the question is : Is there a way to achieve this somehow?</p>
  
  <pre><code>class Foo
  {
      private:
          std::vector&lt;int&gt; m_vec;
  
      public:
          Foo()
          {
              m_vec.push_back(1);
              m_vec.push_back(2);
              m_vec.push_back(3);
          }
  
          //Getter
          int operator()(int i)
          {
              return m_vec.at(i);
          }
  
          //Setter (C2556)
          int&amp; operator()(int i)
          {
              return m_vec.at(i);
          }
  };
  
  int main()
  {
      Foo foo;
      foo(1) = 10; //use the setter 
      int i = foo(1); //use the getter
      return 0;
  }
  </code></pre>