9

OPERATOR OVERLOADING

9.1 INTRODUCTION

Let us consider a situation where we have a class called ‘length’ which represents the length of an item (say cloth) in feet and inches. Its class diagram is shown in Fig. 9.1.

Figure 9.1

Figure 9.1 A class called ‘length’

Now if we desire to add two objects of this class type, one of the options is to use a friend function (say add()) as shown below:

image

The following main() function tests the above given class.

image

A sample ...

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