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

  1. #include <stream.hpp>
  2.  
  3. // test all levels of conversions
  4.  
  5. class complex {
  6.    double r,i;
  7. public:
  8.    complex (double re= 0.0, double im=0.0)  { r=re; i=im; }
  9.    };
  10.  
  11. overload foo;
  12.  
  13. void foo (double d, int x)
  14. {
  15. cout << "level 0 solution\n";
  16. }
  17.  
  18. void foo (double d, long l)
  19. {
  20. cout << "level 1 solution\n";
  21. }
  22.  
  23. #if 0
  24.  
  25. void foo (complex c, int i)
  26. {
  27. cout << "level 2 solution\n";
  28. }
  29.  
  30. #endif
  31.  
  32. main()
  33. {
  34. double d;
  35. int i;
  36.  
  37. foo (d,i);
  38. // level 2 solution:  convert double to complex
  39. // level 1 solution:  convert int to long
  40. // level 0 solution:  exact match
  41. }
  42.  
  43.  
  44. /* results:
  45.    choices present
  46.    0,1,2                0
  47.      1,2                1
  48.    0,  2                0
  49. */
  50.