Function outside of class in C++
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/2425906/operator-overloading-outside-class">Operator overloading outside class</a>  </p>
</blockquote>



<p>I'm not great with C++ but I've been tasked with creating a custom Vector class that uses a lot of operator overloads. I'm having a hard time grasping how to do one of them.
The class should provide functions for the following: </p>

<pre><code>v3 = v2 * 2.0f;
v3 = 2.0f * v2;
</code></pre>

<p>I successfully implemented the first one by overloading the * operator. I'm not sure how to go about the second one though. I know I need to overload the * operator again, but I don't think it should be inside of my vector class. I was absent from class the day my professor explained it, and when I talked to him afterwards he mentioned that it needs to be outside of the class. The problem is that I have no idea how that will work. Any guidance would be great!</p>

<p>EDIT- </p>

<p>@Fede_Reghe That makes sense to me, but when I added it I am now getting this error from the compiler: 
Vector.h:64: error: passing ‘const Vector’ as ‘this’ argument of ‘float Vector::operator’ discards qualifiers</p>

<p>In the header, I have these two lines that refer to the * overloads.
    Vector operator * (float);
    friend Vector operator*(float, const Vector&amp;);</p>

<p>Then I overloaded the [] so that it returns a float of the x, y, or z value. That looks like this in the header:
    float operator [] (int);</p>

<p>Outside of the class, I defined the friend * overload like this:</p>

<pre><code>Vector operator * (float f,const Vector&amp; v2)
 {
    float newX = v2[0] * f;
    float newY = v2[1] * f;
    float newZ = v2[2] * f;
    Vector newVector(newX, newY, newZ);
    return newVector;
 }
</code></pre>

<p>I don't fully understand what the error message means.</p>
