Your operator=
takes its argument by non-const reference. As such, temporaries (such as the object returned by begin()
) cannot bind to it. If you need a custom copy assignment operator, change it like this:
void operator = (const iterator & rhs) {theList = rhs.theList; currentLink = rhs.currentLink;}
In addition, to make the operator conform to the standard library requirements, you should change it to return a reference to the object being assigned to:
iterator& operator = (const iterator & rhs) {
theList = rhs.theList;
currentLink = rhs.currentLink;
return *this;
}
Lastly, do you need a custom assignment operator at all? What yours does is just assignment of members. If they are all members, you're better off removing the operator entirely and relying on the compiler-generated one.