home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / IDIOMS.ZIP / 8-2.H < prev    next >
C/C++ Source or Header  |  1991-12-04  |  1KB  |  57 lines

  1. /* Copyright (c) 1992 by AT&T Bell Laboratories. */
  2. /* Advanced C++ Programming Styles and Idioms */
  3. /* James O. Coplien */
  4. /* All rights reserved. */
  5.  
  6. class Class {
  7. };
  8.  
  9. typedef long Hours;
  10. typedef long Dollars;
  11. typedef long Days;
  12.  
  13. class String {
  14. public:
  15.     String();
  16.         String(const char*);
  17. };
  18.  
  19. class EmployeeId {
  20. public:
  21.     EmployeeId(long);
  22.     EmployeeId();
  23. };
  24.  
  25. class Exemplar { Exemplar(); };
  26.  
  27. class Employee: public Class {
  28. public:
  29.     Employee(Exemplar /* unused */) { }
  30.  
  31.     // the make() functions take the place of constructors
  32.     Class *make() { return new Employee; }
  33.     Class *make(const char *name, EmployeeId id) {
  34.         return new Employee(name, id);
  35.     }
  36.     long printPaycheck();
  37.     void logTimeWorked(Hours);
  38. private:
  39.     // note that constructors are private, meaning that
  40.     // ordinary instances of this class cannot be created
  41.     Employee(): salary(0), vacationAllotted(0),
  42.         vacationUsed(0), name(""), id(0) { }
  43.     Employee(const char *emp_name, EmployeeId emp_id):
  44.         salary(0), vacationAllotted(0), vacationUsed(0)
  45.         {
  46.             name = emp_name;  id = emp_id;
  47.         }
  48.     Dollars salary;
  49.     Days vacationAllotted, vacationUsed;
  50.     String name;
  51.     EmployeeId id;
  52. };
  53.  
  54. // This variable serves as the globally known handle
  55. // to the Employee exemplar object
  56. extern Class *employee;
  57.