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

  1. #include <stream.hpp>
  2.  
  3. // test level 2 conversions
  4. // the constructor gives an implicit conversion from double to complex
  5.  
  6. // with no foo(double), it must promote to complex by itself.
  7.  
  8. class complex {
  9.    double r,i;
  10. public:
  11.    complex (double re= 0.0, double im=0.0)  { r=re; i=im; }
  12.    };
  13.  
  14. overload foo;
  15.  
  16. void foo (int x)
  17. {
  18. cout << "foo(int)\n";
  19. }
  20.  
  21.  
  22. void foo (complex c)
  23. {
  24. cout << "foo(complex)\n";
  25. }
  26.  
  27.  
  28. main()
  29. {
  30. int i;
  31. float f;
  32. double d;
  33. complex c;
  34.  
  35. foo (i);  //int
  36. foo (f);  //float to complex
  37. foo (d);  //doule to complex
  38. foo (c);  //complex
  39. }
  40.