home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / IDIOMS.ZIP / 4-4.C < prev    next >
C/C++ Source or Header  |  1991-12-04  |  961b  |  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. void f(int j) { /* . . . . */ }
  7.  
  8. class A {               // base class (superclass)
  9. public:
  10.     void f(int);
  11.     // . . . .
  12. };
  13.  
  14. class B: public A {     // derived class (subclass)
  15. public:
  16.     void f(double);
  17.     void g(int);
  18.     // . . . .
  19. };
  20.  
  21. void B::g(int k) {
  22.     f(k);               // B::f(double) with promotion
  23.     A::f(k);            // A::f(int);
  24.     this->A::f(k);      // A::f(int);
  25.     ::f(k);             // ::f(int);
  26. }
  27.  
  28. int main() {
  29.     A *a;
  30.     B *b;
  31.     int i;
  32.     // . . . .
  33.     a->f(1);        // A::f(int)
  34.     a->f(3.0);      // A::f(int) with coercion int(3.0)
  35.     b->f(2);        // B::f(double) with promotion double(2)
  36.     b->f(2.0);      // B::f(double)
  37.     b->A::f(7.0);   // A::f(int) with coercion int(7.0)
  38.     b->g(10);       // B::g(int)
  39. }
  40.