template<typename T>
class ListItem
{
public:
T value() const
{
return _value;
}
ListItem *next() const
{
return _next;
}
protected:
private:
T _value;
ListItem *_next;
};
template<typename T>
class List
{
public:
protected:
private:
ListItem<T> *begin;
};
template<typename Item>
class ListIter
{
public:
ListIter();
virtual ~ListIter(){};
Item *ptr;
ListIter(Item *p = 0) : ptr(p){}
Item& operator*() const
{
return *ptr;
}
Item *operator->() const
{
return ptr;
}
//pre increment operator
ListIter& operator++()
{
ptr = ptr->next();
return *this;
}
//post increment operator
ListIter operator++(int)
{
ListIter tmp = *this;
++*this;
return tmp;
}
bool operator==(const ListIter& i) const
{
return ptr == i.ptr;
}
bool operator!=(const ListIter& i) const
{
return ptr != i.ptr;
}
};