7.5 OVERLOADING OF INCREMENT OPERATOR

We have seen overloading unary operators. As increment and decrement operators are unary operators, we can overload them. However, their overloading is bit special. These operators come in both prefix and postfix form. To differentiate between pre- and post-increment, C++ has developed additional form. It uses a dummy parameter declaration “int”. Let us study overloading increment operator for rational numbers.

The declaration

 

images
Box 7.1 Rational Numbers

In mathematics, we define a number as integer, real, rational, irrational or imaginary. Rational numbers are represented by a ratio of two integer numbers. ...

Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.