previous | start | next

## Nested Classes and Name Spaces

- In the standard library, the `iterator` class is nested inside the `list` class.

  >     list<string>::iterator pos = staff.begin();

- The reason is so several different implementations (for vectors, lists, maps, and sets) can all share the same name (iterator), but have different implementations.

  >     vector<double>::iterator p = a.begin();
  >     list<string>::iterator q = b.begin();

- To nest a class inside another, first declare the nested class inside the outer class.

  >     class List
  >     {
  >        ...
  >        class Iterator;
  >        ...
  >     };

previous | start | next