home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / IDIOMS.ZIP / 3-2.C < prev    next >
C/C++ Source or Header  |  1991-12-04  |  837b  |  30 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.  
  8. class String {
  9. public:
  10.     String();              // default constructor
  11.     String(const String&); // copy constructor
  12.     String& operator=(const String&);  // assignment
  13.     ~String();             // destructor
  14.     String(const char*);   // create a String from a "C string"
  15.     String operator+(const String&) const;
  16.                            // redefine "+" to mean catenation
  17.     int length() const;    // length of string in characters
  18.     const char *const C_rep() {
  19.         return (const char *const)rep;
  20.     }
  21. private:
  22.     char *rep;
  23. };
  24.  
  25. int main() {
  26.     String s;
  27.     // . . . .
  28.     printf("string is %s\en", s.C_rep());
  29. }
  30.