home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c100 / 5.ddi / OVLOAD.ZIP / OV9.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-22  |  703 b   |  42 lines

  1. #include <stream.h>
  2.  
  3. class C1 {
  4.    int x;
  5. public:
  6.    void foo (int x);
  7.    };
  8.  
  9. class C2 : public C1 {
  10. public:
  11.    void foo (long x);
  12.    };
  13.  
  14. void C1::foo (int x)
  15. {
  16. cout << "C1::foo()\n";
  17. }
  18.  
  19. void C2::foo (long x)
  20. {
  21. cout << "C2::foo()\n";
  22. }
  23.  
  24. main()
  25. {
  26. C2 cl;
  27. int i;
  28. long l;
  29. char c;
  30.  
  31. cl.foo (i);
  32. cl.foo (l);
  33. cl.foo (c);
  34.  
  35. /* Zortech calls C2::foo() for all three cases.  The int is converted to a
  36.    long rather then calling the base class's foo().  The char is converted
  37.    to a long (which is incorrect) rather then calling the base class's foo().
  38. */
  39. /* BOTH compilers do this.  It seems that the new definition hides the old
  40.    one, rather then overloading it.  */
  41. }
  42.