I've been trying to make some operator overloads (* and +) on a class which is wrapped in smart pointers.
auto p = std::make_unique<Polynomial<T>>();
When I try to overload it using normal overloading, it obviously asks for the smart pointer types.
Edit, so:
std::unique_ptr<Polynomial<T>> operator+(const std::unique_ptr<Polynomial<T>>& right);
template<class T>std::unique_ptr<Polynomial<T>> Polynomial<T>::operator+(const std::unique_ptr<Polynomial<T>>& right) {
//Do stuff
}
And the error:
So how do you go about overloading the normal operators when the class is encapsulated in a smartpointer?
Don't.
Run those operations on the pointees, not on the pointers:
*p = *p + *p
It would be very confusing for users of your code if suddenly pointers had completely different and unexpected semantics.
It would be confusing for you, too.
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