home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK4 / SAMPLES / CPPTUTOR / FRAC1.H$ / FRAC1
Encoding:
Text File  |  1991-12-11  |  1.0 KB  |  34 lines

  1. // FRAC1.H
  2.  
  3. // This is an example class from Chapter 8 of the C++ Tutorial. This
  4. //     class demonstrates the overloaded binary + operator, the
  5. //     overloaded unary - operator, and two user-defined conversions:
  6. //     one using a conversion operator, and one using a single-argument
  7. //     constructor. This class results in ambiguity errors when you
  8. //     compile statements like a = b + 1234 (where a and b are Fraction
  9. //     objects), because the compiler cannot decide which user-defined
  10. //     conversion to use.
  11.  
  12. #if !defined( _FRAC1_H_ )
  13.  
  14. #define _FRAC1_H_
  15.  
  16. class Fraction
  17. {
  18. public:
  19.     Fraction();
  20.     Fraction( long num, long den = 1 );
  21.     void display() const;
  22.     operator float() const;
  23.     friend Fraction operator+( const Fraction &first,
  24.                                const Fraction &second );
  25.     friend Fraction operator-( const Fraction &one );
  26. private:
  27.     static long gcf( long first, long second );
  28.     long numerator,
  29.          denominator;
  30. };
  31.  
  32. #endif // _FRAC1_H_
  33.  
  34.