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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.