Hello,
I am trying to make a constant iterator data structure, I have a normal Iterator data structure done, but I'm a little stumped with the const iterators.. can you please point me in the right direction?
This is my data structure for the iterators:
template <typename T>
class Iter : public std::iterator<std::forward_iterator_tag, T, void>
{
public:
//default constructor
Iter() : cur (0), the_list (0) { }
//copy constructor
Iter(Iter<T>& i) {
cur = i.cur;
the_list = i.the_list;
}
bool operator==(Iter<T>& i) const
{
return cur == i.cur;
};
bool operator != (Iter<T>& i) const
{
return cur != i.cur;
};
//Iterator basic functions
T& operator*(); //retrieve data
Iter& operator++(); //increment
Iter operator++ (int);
Iter& operator--(); //decrement
Iter operator--(int);
private: //data member of class Iter.
friend class List <T>;
friend class cIter<T>;
Node<T> *cur;
List<T> *the_list; //hooked to a particular list
//constructor accessible only from friend class
Iter (List<T> *l, Node<T> *n) : the_list(l), cur(n) { };
};
Thanks so much.