previous | start | next

## Common Uses for Pointers (Optional Attributes)

- One use for pointers is optional attributes.
- If the attribute is needed, the pointer is set to the address of the object; otherwise the pointer will be set to `NULL`.

  >     class Department
  >     {
  >      . . .
  >     private:
  >        string name;
  >        Employee* receptionist;
  >     };

- This is better than allocating space for an object that might not be used.

  >     class Department // modeled without pointer
  >     {
  >      . . .
  >     private:
  >        string name;
  >        bool has_receptionist;
  >        Employee receptionist;
  >     };

previous | start | next