What is a friend function?
Private data members cannot be accessed from outside the class. However, situations arise where two classes need to share a particular function. For such situations, C++ introduces friend functions. These are functions that can be made friendly with both the classes, thus allowing these functions to have an access to the private data of these classes.