title: how to return a reference of a vector element from a function operator(x,y)
body: <p>I have a class template which contains a vector of T as a protected member variable. I want to overload the operator() so that it returns a reference of the vector's element in line y and column x. </p>
  
  <p>When i declare the operator() function as:</p>
  
  <pre><code>template &lt;class T&gt;
  T &amp; ArrayT&lt;T&gt;::operator()(unsigned int x, unsigned int y)const{
      return buffer[y*width + x];
  }
  </code></pre>
  
  <p>i get C2440 error: 'return': cannot convert from 'const_Ty' to 'T&amp;'</p>
  
  <p>If i declare the operator function as:</p>
  
  <pre><code>template &lt;class T&gt;
  const T &amp; ArrayT&lt;T&gt;::operator()(unsigned int x, unsigned int y)const{
      return buffer[y*width + x];
  }
  </code></pre>
  
  <p>then my code compiles but if for example i create a derived templeted class where T is float and i write (obj is an object of the derived class with a member variable vector of floats): </p>
  
  <pre><code>float f=obj(i,j); 
  f=pow(f,2);
  </code></pre>
  
  <p>then nothing seems to happen. The float in the position i,j inside the vector does not change so assume that i dont really work on a reference, because if a reference was returned by the operator () the above lines should change the element in position (i,j) right?</p>
  
  <p>I am new to c++ and i understand i might be doing some very silly mistakes here, but please any kind of help woulb be welcome.</p>