This means that the friend is not a member of the class, but you can access static class members and member types (including private ) without qualification.
This makes the function "look and feel" like a member. Since operator<< is closely tied to logWrapper , it’s intuitive that you can implement it as if it were a member of a class.
But remember that this is not a member! This is just a free feature with special access privileges, as if it were defined externally.
Edit: since there are no static elements and no member types, this makes no difference here. You can move a friend’s definition outside without changing it. However, this style is idiomatic because you could. Often it is used with templates, which often have member types / typedefs.
In fact, defining a friend inside a template<…> class block is the only way to define a template function without a template. This esoteric and sometimes elusive beast, however, is sometimes very convenient. Usually its creation is random, even impartial, so I will not participate in this discussion ...
Potatoswatter
source share