In C++, we are allowed to define a friend function inside the class definition like:-
class A {
public:
A(int a): mem(a){}
~A() {}
friend void fun() {}
private:
int mem;
};
void fun();
and then we can call this function, just like any regular function.
fun();
Can someone explain about (with examples):
In what cases do we need to define friend function inside the class definition.
What is special about this kind of definition which can not be achieved with just declaring function as friend in class and then defining the function outside.