7.1 INTRODUCTION

We have seen arithmetic operators working with numeric data types. There are certain classes like rational_number, complex_number, etc. which are numbers of some kind. C++ designers felt that it would be convenient for programmers to use operators with these data types. Therefore, they decided to add concept of operator overloading in the language. It allows operands to be objects. Once operators work with objects, there are many situations when we would like to use this facility to non-numeric objects too! Let us first see two concrete examples with objects which are numeric in nature.

Example 1:

If k is an integer, then k++ has the normal meaning of incrementing k by 1. Now, suppose we have an object num1 of class rational_number. ...

Get Object Oriented Programming with C++, Second 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.