13 Operator Functions: Doing It with Class
After reading Chapter 12, you know how to write classes (object types) that work just like standard data types, right?
Well, almost. One of the most important features of a standard data type such as int, float, double, and even char, is that you can perform operations on them. In fact, without these operators, it would be difficult to perform any calculations in C++ at all.
C++ lets you define how to perform these same operations (such as +, -, *, and /) on objects of your own classes. You can also define how a test-for-equality is carried out, letting you determine whether two quantities are equal.
The benefit of this C++ capability is that it enables you to declare new classes that, for nearly all ...
Get C++ Without Fear: A Beginner’s Guide That Makes You Feel Smart 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.