I am trying to figure out how to correctly overload operators.
Q#1: Is there something wrong with my code/can it be written better?
Q#2: Is it ok to have this in header file only?
// Vector2.hpp:
template <class T>
class Vector2 {
public:
Vector2(T x, T y) {
this->x = x;
this->y = y;
}
T x;
T y;
Vector2<T> operator+=(const Vector2<T>& other) {
return Vector2<T>(this->x + other.x, this->y + other.y);
}
Vector2<T> operator+(const Vector2<T>& other) {
return Vector2<T>(this->x + other.x, this->y + other.y);
}
};