I'm trying to overload the +=
operator for a simple mathematical Vector
class, to sum the elements of two vectors, like this:
vector1 += vector2
Part of Vector2D.h
:
#ifndef _VECTOR2D_H_
#define _VECTOR2D_H_
class Vector2D
{
public:
Vector2D():x(0),y(0){}
~Vector2D(){}
/* All the mathematical operation ... */
// Overloading operators
Vector2D& operator+=(const Vector2D& rhs);
Vector2D& operator*=(const Vector2D& rhs);
Vector2D& operator/=(const Vector2D& rhs);
Vector2D& operator-=(const Vector2D& rhs);
private:
double x;
double y;
};
Then part of Vector2D.cpp
:
#include "Vector2D.h"
Vector2D& Vector2D::operator+=(const Vector2D& rhs)
{
x += rhs.x;
y += rhs.y;
return *this;
}
Now, in the .cpp
class, I want to use the operator:
void MovingObject::move()
{
m_pVelocity += m_pAcceleration;
m_pVelocity->limit(m_fMax_speed);
m_pPosition += m_pVelocity();
m_pAcceleration->zero();
}
The variables m_pVelocity
, m_pAcceleration
and m_pPosition
are all Vector2D*
pointers.
When I try to compile, this is what I get from the compiler:
Why does this happen? I've read a lot of papers, and I've seen a lot of examples, and all of them work, but mine does not.
Am I missing something?