IMHO, almost never.
"friend" is often used to break encapsulation, as it allows an external object to access the personal data of your class. You almost never want to do this - it is often better / safer to expose “semi-private” data through public accessors (which can validate) than expose personal information to another class (which can thrombose on you).
However, sometimes you will have a couple / group of very closely related classes, where it makes sense to keep them as separate classes, but they need low-level access to data that really should not be shared with the world as a whole. This is where a "friend" can be used - with caution.
As a general rule, try to limit the amount of friends (for example, friend methods, not friend classes) to minimize areas where direct access to sensitive data is allowed. Remember, another programmer reading your code might think that “private” means that the data is really confidential and can be confused by friends. In addition, the more friends you use, the harder and harder it is to maintain your design. They may be useful, but make sure you have a good rationale for each use.
source share