home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / IDIOMS.ZIP / 3-16.C < prev    next >
C/C++ Source or Header  |  1991-12-04  |  778b  |  29 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. #include <stdlib.h>
  7. #include <string.h>
  8.  
  9. class String {
  10. private:
  11.           static String *newlist;
  12.           union {
  13.                String *freepointer;
  14.                char *rep;
  15.           };
  16.           int len;
  17. public:
  18.           enum { POOLSIZE = 1000 } ;
  19.           String() { rep = new char[1]; *rep = '\e0'; }
  20.           String(const char *s) {
  21.               rep = new char[::strlen(s)+1];
  22.               ::strcpy(rep,s);
  23.           }
  24.           ~String() { delete[] rep; }
  25.     void  *operator new(size_t);
  26.     void  operator delete(void*);
  27.           // . . . .    // other interesting operations
  28. };
  29.