Friend function And Friend Class
- The concept of friend function goes against the concept of date hiding.
- The friend function is declared within the class and it is defined outside of the class.
- The friend function is not a member function of the class.
- Since friend function is not the member function of the class. It is not called for any object, rather objects are passed as parameters to it.
- Even if friend function is not a member function of the class. It can access private member of the class.
- The concept of friend function is useful when a function act as friend function of two more classes.
Consider the following example.
Develop a class period represented in hours and minutes. The class should have following member function.
1)Setperiod ( ) 2) getperiod ( ) 3) display ( ) Define a fn add as a friend fn of class period .It will add two periods and should return answers of the addition.
Write suitable main fn