| Introduction to OOP | Chapter 15: Overloading : | next | previous | audio | real | text |
class Fraction {
public:
Fraction (int top, int bottom) { t = top; b = bottom; }
int numerator() { return t; }
int denominator() { return b; }
private:
int t, b;
};
ostream & operator << (ostream & destination, Fraction & source)
{
destination << source.numerator() << "/" << source.denominator();
return destination;
}
Fraction f(3, 4);
cout << "The value of f is " << f << '\n';