5.12 FRIEND CLASSES
Declaration of friend is not restricted to methods only. You can declare one class as friend as other. For example,
class ABC { // some data members // some member functions friend XYZ ; }
In this declaration, class XYZ is declared as a friend of class ABC. It implies that class XYZ can use all of data members and member functions (private no bar!) in its definition.
We can rewrite the above program to reflect this principle.
Problem: Rewrite Program 5.9 with following modifications. Declare class RefBooks as friend in class TextBooks. Declare method ttlval() in class RefBooks with object of class TextBooks as parameter(pass by value). Do not use any friend function.
Solution: See Program ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access