O'Reilly logo

Object-Oriented Programming with C++ by A.K. Sharma

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

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 ...

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