May 2012
Intermediate to advanced
679 pages
16h 56m
English
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.
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: ...
Read now
Unlock full access