I have overloaded dereference operator for my template class:
template <class T> class Node {
public:
T *pointer;
T operator*() { return *pointer; }
};
I want to be able to write to the pointer in main:
Node<int> n;
*n = 33;
But I get this error:
lvalue required as left operand of assignment
How should I overload this operator to be able to write to the pointer?
Just give it T&
as the return type. Then you have an lvalue. The problem right now is that you're returning a copy of the object pointed to.
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