I'm new to overloading operators, I did some search and found this helpful article, I wrote my own code like the author did but I get vector vector::operator*(float, vector) must take either zero or one argument
error.
Here is my code:
class vector
{
public:
float x;
float y;
vector(float, float);
float operator$ (vector, vector);
vector operator* (float, vector);
vector operator* (vector, float);
};
vector::vector(float _x = 0, float _y = 0)
{
x = _x;
y = _y;
}
const float vector::operator$ (const vector &v1, const vector &v2)
{
return (v1.x * v2.x) + (v1.y * v2.y);
}
const vector vector::operator* (const float &m, const vector &v)
{
vector ret_val = v;
ret_val.x *= m;
ret_val.y *= m;
return ret_val;
}
const vector vector::operator* (const vector &v, const float &m)
{
return m * vector;
}
My operating system is kubuntu 12.04
and my IDE is dev-C++
running on linux using wine windows program loader.
$
..... – Daily