Listing 8 Defines a static data member to prevent access by non-member data functions to access count

//
// list.h - list interface using a nested class
// with a static data member for counting the object
//

class list
       {
public:
       list(unsigned n);
       ~list();
       void add(unsigned n);
       void print();
       static unsigned howmany();
private:
       struct node
              {
              node(unsigned n, node *p);
              unsigned number;
              node *next;
              };
       node *first, *last;
       static unsigned count;
       };

inline unsigned list::howmany()
       {
       return count;
       }

// End of File