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

  1. #include <stream.h>
  2.  
  3. class C1 {
  4.    int x;
  5. public:
  6.    void foo (double x);
  7.    void foo (int x);
  8.    };
  9.  
  10. class C2 : public C1 {
  11. public:
  12.    void foo (long x);
  13.    };
  14.  
  15. void C1::foo (int x)
  16. {
  17. cout << "C1::foo(int)\n";
  18. }
  19.  
  20. void C1::foo (double x)
  21. {
  22. cout << "C1::foo(double)\n";
  23. }
  24.  
  25. void C2::foo (long x)
  26. {
  27. cout << "C2::foo()\n";
  28. }
  29.  
  30. main()
  31. {
  32. C2 cl;
  33. C1 cl1;
  34. int i;
  35. long l;
  36. char c;
  37. double d;
  38.  
  39. cl.foo (i);
  40. cl.foo (l);     /* 2 */
  41. cl.foo (c);
  42. cl.foo (d);     /* 3 */    //warning: double assigned to long
  43.  
  44. cl1.foo (i);
  45. // cl1.foo (l); /* 6 */    //will not compile: bad argument list
  46. cl1.foo (c);
  47. cl1.foo (d);
  48.  
  49. /*     Guidelines C++
  50.     All calls to c2.foo() call C2::foo(), even if it meant converting
  51.     a double to a long.  In (3), this was done even when the public
  52.     base class had a foo(double) it could use.  This contradicts my
  53.     hypothesys.  It seems instead that if a class contains a member function,
  54.     then base class member functions of the same name are not inherrited.
  55.  
  56.     As an aside, notice that the compiler gave a warning when it found
  57.     no function foo(double), but is casted it to a long and continues.  But
  58.     when it found no match for foo(long), it caused an error and did NOT
  59.     continue.  I would have expected it to use foo(double) and continue.
  60. */
  61.  
  62. }
  63.