Is it not supposed for a friend function to be explicitly defined outside of a class ?
Friend functions can be defined (given a function body) inside class declarations. These functions are inline functions, and like member inline functions they behave as though they were defined immediately after all class members have been seen but before the class scope is closed (the end of the class declaration). Friend functions that are defined inside class declarations are in the scope of the enclosing class.
quote
Is it only OK with some operators such as < operator or is it applicable to all operators?
It is best to try to avoid friend functions since they are opposite to what you are trying to do using a private class scope and mainly “hide” the variables. If all your functions are friend functions then what is the use of having private variables?
Still, there are some common operators which are often declared as friend functions, those are operator<<
and operator>>