In the above program, the friend fucntion printArea( ) is declared inside Shape class. So, the private data can be accessed from this function.
SOME POINTS TO REMEMBER:
- Friend function can be invoked like a normal function without the help of any object.
- It cannot access the member names directly and to access them it has to use object name and dot operator with each member name (B.x).
- Friend function can be declared either in public or private class.
- The friend class can access the private and protected members of other class in which it is declared as friend.
- It is also useful to allow a particular class to access the private members of other class.