title: How to properly return reference to class member?
body: <pre><code>class Foo {
      protected:
      QPoint&amp; bar() const;
  
      private:
      QPoint m_bar;
  };
  
  QPoint&amp; Foo::bar() const {
      return m_bar;
  }
  </code></pre>
  
  <p>I got this error:</p>
  
  <p>error: invalid initialization of reference of type ‘QPoint&amp;’ from expression of type ‘const QPoint’</p>
  
  <p>However it works if I change it to this:</p>
  
  <pre><code>QPoint&amp; Foo::bar() const {
      return (QPoint&amp;) m_bar;
  }
  </code></pre>
  
  <p>1) I don't understand why the compiler says that my QPoint is const.</p>
  
  <p>2) Is it ok to leave the cast there? </p>