O'Reilly logo

SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

What Does It Mean to Overload an Operator?

You have seen a variety of operators in C++, ranging from + and - to +=, <<, and ++. Most of these operators have well-defined meanings and apply to a fairly wide range of types, but none of them applies to user-defined types such as structs and classes. This is not especially surprising. After all, what does it mean to add two instances of aRequest together?

On the other hand, as you saw in the example that used std:string to assemble messages for runtime_error (Lesson 11, “switch Statements, static Variables, and runtime_errors”), it can be very convenient to “add” two objects of a class together. The result in that case was a string object that combined the two string objects from the right and left ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required