I am trying to create an iterator class as a member class of the list class and trying to overload the indirectness operator (*) to access the list that it points to:
template<class T> T list<T>::iterator::operator*(iterator& iter) { return ((iter.lstptr)->current)->data; }
where lstptr is a pointer to a list, current is a pointer to a node class, and node class contains a data item of type T
An iterator is declared as follows:
template<class T> class list { public: class iterator; }; template<class T> class list<T>::iterator {
I can compile the function definition of the overloaded * fine operator, but when I try to do something like:
list<int> lst1; lst1.add(6); list<int>::iterator IT; IT = lst1;
The error I get says <1> that I am using illegal indirectness, and <2> that it cannot convert from the :: iterator to int list. Both errors are found on the fourteenth line.
Does anyone know what I'm doing wrong, and how can I properly overload the indirectness operator?
NB: If you need to see more code, tell me which part, because I do not want to put all the code here, because it contains 205 lines and 204 of these lines are not (I think) any errors.
c ++ operator-overloading indirection
user98188
source share