It is incorrect to define a friend function inside a class .
We use a friend function to provide access to private members of a function class.
If we define a friend function within a class, then in a sense it becomes a member of the class data , and we know that the data member of its own class has access to its private members.
Therefore, if you really want to use the friend concept in C ++, declare it outside the private class.
source
share