10.1 Introduction
This chapter shows how to enable C++’s operators to work with class objects—a process called operator overloading. One example of an overloaded operator built into C++ is <<
, which is used both as the stream insertion operator and as the bitwise left-shift operator (which is discussed in Chapter 22). Similarly, >>
also is overloaded; it’s used both as
the stream extraction operator—defined via operator overloading in the C++ Standard Library—and
the bitwise right-shift operator—defined as part of the C++ language.
You’ve been using overloaded operators since early in the book. Various overloads are built into the base C++ language itself. For example, C++ overloads the addition operator (+
) and the subtraction operator ( ...
Get C++ How to Program, 10/e 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.