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

  1. #include <stream.hpp>
  2.  
  3. class C1 {
  4.    int x;
  5. public:
  6.    void foo (long 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 (long x)
  21. {
  22. cout << "C1::foo(long)\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.  
  38. cl.foo (i);
  39. cl.foo (l);
  40. cl.foo (c);
  41.  
  42. cl1.foo (i);
  43. cl1.foo (l);
  44. //cl1.foo (c);  //Zortech will not compile this line.
  45.  
  46. /* try adding another definition to the base class.  This will test to see
  47.    if there is an "overloaded mode" that the translator is in to activate
  48.    searching.  */
  49. /* the first set still converts everything to long and calls C2::foo().  The
  50.    second set, added as a control, calls foo(int) for int and char types. */
  51. /* Zortech gives the same results, except it will not compile the last call.
  52.    It cannot decide whether to convert the char into an int or a long. */
  53.  
  54. /* conclusions:  The current class is searched for a solution.  I presume that
  55.    if no match was found after trying user-supplied conversions it would
  56.    consider base class functions inherited. Tests 9 & 10 do not give
  57.    any evidence toward this, so I use this as a hypotises for the next test.
  58.    It does not tell me the precidence of member functions with an implicit 
  59.    recievier and global functions.  */
  60. }
  61.