title: Class function returning invalid lvalue
body: <p>Hi I am now writing a program handling matrix manipulation and I am struggling on the error handling issue in a member function.</p>
  
  <p>Given a function </p>
  
  <pre><code>double &amp; MATRIX::elements(int i, int j) const;
  </code></pre>
  
  <p>it is the function that can return a reference back, so the function can be a 
  lvalue, e.g. </p>
  
  <pre><code>object.elements(1,2)= 2; // I can change the value matrix element (1,2) to be 2
  </code></pre>
  
  <p>I assume that some people may enter the index of the matrix wrongly (i.e.invalid value of i and j) that the element (i,j) does not exist. Therefore, I write an if-else statement, however, I wonder what should I return when invalid values of i and j are found?? Can I prevent the function from returning  anything so situations like </p>
  
  <pre><code>object.elements(100,100000)= 2; // where the matrix size is only 3x3
  </code></pre>
  
  <p>won' t happen??</p>
  
  <p>P.S. I store the matrix elements in a dynamic array when I create the object</p>