home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / IDIOMS.ZIP / 2SMF.C < prev    next >
C/C++ Source or Header  |  1991-12-04  |  592b  |  26 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 X {
  9. public:
  10.     // ...
  11.     void foo() { fooCounter++;  /* . . . . */ }
  12.     static void printCounts() {
  13.         printf("foo called %d times\en", fooCounter);
  14.     }
  15. private:
  16.     static int fooCounter;
  17. };
  18.  
  19. int X::fooCounter = 0;
  20.  
  21. int main() {
  22.     // printCounts();     // error (unless there really
  23.                        //        is a global function f())
  24.     X::printCounts();  // fine
  25. }
  26.