heres my class
class Vector
{
public:
Vector();
Vector(float x, float y, float z);
float x;
float y;
float z;
Vector &operator+(const Vector &other) const;
Vector &operator+=(const Vector &other);
Vector &operator*(float n) const;
};
//op overloading functions impl
Vector &Vector::operator+(const Vector &other) const
{
Vector result = *this;
result.x += other.x;
result.y += other.y;
result.z += other.z;
return result;
}
Vector &Vector::operator+=(const Vector &other)
{
this->x += other.x;
this->y += other.y;
this->z += other.z;
return *this;
}
Vector &Vector::operator*(float n) const
{
Vector result = *this;
result.x *= n;
result.y *= n;
result.z *= n;
return result;
}
I am getting incorrect result when trying to use more complex equation. For example this WORKS:
Vector vChange = velocity * time;
position += vChange;
while this DOESNT:
position += velocity * time;
i.e. it compiles and runs but writes some bogus into position
Same for this one:
Vector& Reflect(const Vector& I, const Vector& N)
{
Vector v = I - 2 * Dot(N, I) * N;
}
Could you advise me what am I doing wrong? Thanks!