#include template class List { public: struct Node { Node* next; T info; }; class Iterator { private: Node* current; public: explicit Iterator(Node* c) { current = c; } T* next() { T* ret = ¤t->info; current = current->next; return ret; } bool hasNext() 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); List::Iterator it=list.iterator(); while(it.hasNext()) { int* next = it.next(); *next = *next * 10; } printf("Begin list\n"); it=list.iterator(); while(it.hasNext()) { int* next = it.next(); printf(" %d\n", *next); } printf("End list\n"); }