title: Operator overload = and const reference
body: <p>I'm trying to construct a class for colors in C++,<br>
  this is not an homework is just that I'm still struggling with references and const.</p>
  
  <p>--Color.h</p>
  
  <pre><code>class Color{
  private:
      double r;
      double g;
      double b;
      double a;
  public:
      //constructor, getters and setters...
      Color&amp; operator =(Color&amp; other_color); //(1)
  }
  </code></pre>
  
  <p>--Color.cpp</p>
  
  <pre><code>Color&amp; operator=(Color&amp; other_color){
       this-&gt;r = other_color.get_r(); //line 41
       this-&gt;b = other_color.get_b();
       //and so on...
       return *this;
  }
  </code></pre>
  
  <p>like this it works fine but I heard one has to put a const to avoid that by fault the object will be modified by the assignement operation, so one has to declare the other object as const. Like this:</p>
  
  <pre><code>Color&amp; operator =(Color const&amp; other_color); //(2)
  </code></pre>
  
  <p>but it gives me this errors:  </p>
  
  <pre><code>/Users/../color.cpp:41: error: passing 'const Color' as 'this' argument of 'float Color::get_r()' discards qualifiers
  </code></pre>
  
  <p>so here is my question...</p>
  
  <p>what is happening here? second what would happen if I don't declare <strong>other_color</strong> as const? what are the possible errors?</p>
  
  <p>PS.: little bonus question:<br>
  I want to pass my variable to the opengl glColor4v(colorx.return_rgba()) returning the array [r,g,b,a] of the class Color. This:</p>
  
  <pre><code>float* Color::return_rgba(){
      float  rgba[4] = {this-&gt;r, this-&gt;g, this-&gt;b, this-&gt;a};
      return rgba;
  }
  </code></pre>
  
  <p>won't work because rgba won't be in scope anymore after the return so it will be deleted and my pointer will point to not initialized adresses, damn...</p>