In most cases, good programming style says you should not use friend classes or functions. The entire concept of object-oriented programming languages (like C++ or Python) is that the world should see your classes only through their API (in other words, their public methods). This means you can change the implementation of the class internally, but if the external API stays the same, users of the class will not see and changes.

Friend classes are sometimes useful if you have two classes that tightly cooperate with each other. One class might serve as the public interface for a set of features, but there might be another class that really does all of the work. In that case, you might make the second class a "friend" of the first, so the second class could update variables or call protected or private methods in the first class.

Friend classes are also sometimes used when deriving a new class by inheriting the first one is not appropriate. For example, a second class might contain a member variable for an instance of the first class, and needs to call protected functions in order to update it. Deriving from the first class is not a good solution, because the second class might not obey the "is-a" rule for object hierarchies. (A derived class must be - "is-a" - class that can be treated as if it was the base class. A coin and a bill are both "money").

An instance where a friend class might be useful:

You have an electronic cash gift card. You can use an card kiosk to read the value stored in the card, but you can't change the value. In an API, this means that the Card:: getValue() method is public, but the Card:: setValue() method is not. However, you can use another kiosk to deposit cash and have it credited to the card. In this case, the Kiosk class might be declared as a "friend" of the Card class, and so the Kiosk class would be able to call the Card:: setValue() method to update the value of the card.

Deriving Kiosk from Card does not make sense, because a Kiosk "is not a" Card.

Hope this helps. No doubt, Google could give you a much better explanation. Try "use case for C++ friend class". Lots of useful hits.