10. Operator Overloading; Class string
There are two men inside the artist, the poet and the craftsman. One is born a poet. One becomes a craftsman.
—Emile Zola
A thing of beauty is a joy forever.
—John Keats
Objectives
In this chapter you’ll:
• Learn how operator overloading can help you craft valuable classes.
• Overload unary and binary operators.
• Convert objects from one class to another class.
• Use overloaded operators and additional features of the string
class.
• Create PhoneNumber
, Date
and Array
classes that provide overloaded operators.
• Perform dynamic memory allocation with new
and delete
.
• Use keyword explicit
to indicate that a constructor cannot be used for implicit conversions.
• Experience a “light-bulb moment” when you’ll ...
Get C++ How to Program, Ninth Edition 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.