Introduction to OOP Chapter 15: Overloading : next previous audio real text

Easy to Extend

Since output uses overloading, it is very easy to extend to new types.
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';
Intro OOP, Chapter 15, Slide 09