Operator Overloading for Nonnumeric Classes

As I noted in the introduction to this chapter, the extension of built-in operators to numeric classes is natural. Overloaded operator functions for these classes are very similar to built-in operators. Misinterpretation of their meaning by the client programmer or by the maintainer is not likely. The idea of treating values of built-in types and programmer-defined types equally is a sound one that lends itself to straightforward implementation.

Operators can be applied to the objects of nonmathematical classes as well, but the meaning of addition, subtraction, and other operators might be stretched. This is similar to the story of icons for command input in the graphical user interface.

In the beginning, ...

Get Core C++ A Software Engineering Approach 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.