Operator Overloading
Let's look at a technique for giving object operations a prettier look. Operator overloading is another example of C++ polymorphism. In Chapter 8, “Adventures in Functions,” you saw how C++ enables you to define several functions having the same name as long as they have different signatures (argument lists). That was function overloading, or functional polymorphism. Its purpose is to let you use the same function name for the same basic operation even though you apply the operation to different data types. (Imagine how awkward English would be if you had to use a different verb form for each different type of object—lift_lft your left foot, but lift_sp your spoon.) Operator overloading extends the overloading concept to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access