title: invalid initialization of non-const reference when returning an array element
body: <p>I'm writing a class that wraps a dynamically allocated array and I'm trying to write the operator[] function. Currently I have:</p>
  
  <pre><code>bool&amp; solution::operator[](unsigned int pos)
  {
    if(pos &lt; _size)
    {
      return this-&gt;_data[pos];
    }
    else
    {
      return false;
    }
  }
  </code></pre>
  
  <p>But I get the following error from g++:</p>
  
  <p><code>error: invalid initialization of non-const reference of type ‘bool&amp;’ from an rvalue of type ‘bool’</code></p>
  
  <p>How should I be doing this? I need the [] operator to be able to modify elements.</p>