Hi, suppose this class:
Qt Code:
  1. class Foo {
  2.  
  3. protected:
  4. QPoint& bar() const;
  5.  
  6. private:
  7. QPoint m_bar;
  8. };
  9.  
  10. QPoint& Foo::bar() const {
  11. return m_bar;
  12. }
To copy to clipboard, switch view to plain text mode 

I get this error:

error: invalid initialization of reference of type ‘QPoint&’ from expression of type ‘const QPoint’

However it works if I change it to this:

Qt Code:
  1. QPoint& Foo::bar() const {
  2. return (QPoint&) m_bar;
  3. }
To copy to clipboard, switch view to plain text mode 

1) I don't understand why the compiles says my QPoint is const.
2) Is it ok to leave the cast there?