7.4 FRIEND FUNCTIONS IN OPERATOR OVERLOADING

We have seen friend functions earlier. In this section, we will discuss its role in operator overloading. Let us start where we left it in previous section. In binary operator overloading case 3 friend function is a must.

7.4.1 Binary operator overloading [case 3]

We have just seen a program 7.3 for calculating the interest. This can serve as an appropriate example for this case in class IndCur, we have to replace declaration

IndCur operator * (float rate ) ;

by

friend IndCur operator * ( float rate, IndCur m) ;

And replace the corresponding method accordingly. Now you can write a statement:

Amt2 = 0.12 * amt1 ;

Problem: Write a program to demonstrate binary operator overloading of case 3.

Solution: ...

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.