src: i.ytimg.com
A friend class in C++ can access the private and protected members of the class in which it is declared as a friend.
Video Friend class
Rationale
Friendship may allow a class to be better encapsulated by granting per-class access to parts of its API that would otherwise have to be public. This increased encapsulation comes at the cost of tighter coupling due to interdependency between the classes.
Maps Friend class
Example
src: slideplayer.com
Properties
- Friendships are not symmetric - if class
Ais a friend of classB, classBis not automatically a friend of classA. - Friendships are not transitive - if class
Ais a friend of classB, and classBis a friend of classC, classAis not automatically a friend of classC. - Friendships are not inherited - if class
Baseis a friend of classX, subclassDerivedis not automatically a friend of classX; and if classXis a friend of classBase, classXis not automatically a friend of subclassDerived.
src: i.ytimg.com
See also
- Friend function
src: classpass.com
References
src: i.ytimg.com
External links
- http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8a.doc%2Flanguage%2Fref%2Fcplr043.htm
- http://www.cplusplus.com/doc/tutorial/inheritance/
Source of article : Wikipedia
