C++ Friend Function is used to access the private and protected members of the class.  Private and Protected data members of the class can only be accessed through member functions of that particular class, but through the friend function, we can access those data members.  The declaration of the friend function is inside the class of whose private and protected data members we want to access.

C++ Friend Function

A friend function of the class is defined outside that class’ scope, but it has a right to access all the private and protected members of a class. Even though the prototypes for friend functions appear in the class definition, friends are not member functions.

#c++ #c++ friend function

C++ Friend Function Example | Friend Function In C++
6.75 GEEK