#include template class List { public: struct Node { Node* next; T info; }; class Iterator { private: Node* current; public: explicit Iterator(Node* c) { current = c; } T& operator*() const { return current->info; } T* operator->() const { return ¤t->info; } void operator++() { current = current->next; } bool isValid() const { return current != nullptr; } }; private: Node* first; Node** pLast; public: List() { first = nullptr; pLast = &first; } void add(T val) { *pLast = new Node; (*pLast)->next = nullptr; (*pLast)->info = val; pLast = &(*pLast)->next; } bool isEmpty() const { return first == nullptr; } Iterator iterator() { return Iterator(first); } }; int main() { List list; list.add(10); list.add(12); list.add(42); for(List::Iterator it=list.iterator() ; it.isValid() ; ++it) { *it = *it * 10; } printf("Begin list\n"); for(List::Iterator it=list.iterator() ; it.isValid() ; ++it) { printf(" %d\n", *it); } printf("End list\n"); }