Since a friend function is not a member of a class, can it be used for two classes for performing the same job? I guess no because we've to pass an object of that class in which we're playing.
if same function is to be done in two classes, then it should be better to make a friend function which performs the same task required in both classes.
Two classes can name to same friend, does this have any benefit?
@Rehan FASTian
if same function is to be done in two classes, then it should be better to make a friend function which performs the same task required in both classes.
The same function can not do the same task in two classes in C++ if the classes do not belong to one class hierarchy.
It is possible only when the function deals with two classes simultaneously. In this case it is declared as a friend function for both classes.
Two classes have different members. So any one function can not do the same task for different classes. It need to have access to members of the both classes simultaneously and explicitly specify their names..