Function declaration:
template <typename T>
Point<T>* operator +(Point<T> const * const point, Vector<T> const * const vector);
It's been a while since I've used C++ so maybe I'm doing something really stupid. Let me know.
Also, no, I am not using namespace std.
What you're doing wrong here on the language level is overloading operators for pointers. At least one argument of an overloaded operator must be of a user-defined type, or a reference to one.
But you're also doing this wrong on another level. You're returning a pointer, which means you will probably need to allocate some storage dynamically in the operator. Well, who owns that storage? Who will release it?
You should just take references and return by value, something like:
template <typename T>
Point<T> operator +(Point<T> const& point, Vector<T> const& vector) {
return Point<T>(point.x + vector.x, point.y + vector.y);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With