home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / IDIOMS.ZIP / 2FUNCP.C < prev    next >
C/C++ Source or Header  |  1991-12-04  |  890b  |  40 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 String {
  7. public:
  8.     int curColumn() { return 0; }
  9.     int length() { return 0; }
  10.     int hash() { return 0; }
  11. };
  12.  
  13. class Stack {
  14. public:
  15.     char pop(int) { return 'a'; }
  16.     void push(char) { }
  17. };
  18.  
  19. class PathName:public String {
  20. public:
  21.     int error(int, const char * ...) { return 0; }
  22. };
  23.  
  24. int  (String::*p1)() = String::length;
  25. char (Stack::*p2)(int) = Stack::pop;
  26. void (Stack::*p3)(char) = Stack::push;
  27. int  (PathName::*p4)(int, const char* ...) = PathName::error;
  28.  
  29. int main() {
  30.     String s;
  31.     Stack t;
  32.     PathName pn1, *pn2 = new PathName;
  33.  
  34.     int m = (s.*p1)();
  35.     char c = (t.*p2)(2);
  36.     (t.*p3)('a');
  37.     (pn1.*p4)(1, "at line %d\n", __LINE__);
  38.     (pn2->*p4)(3, "another error (%d) in file %s", __LINE__, __FILE__);
  39. }
  40.