In this particular case, the namespace is really redundant, because by default the variables of the const namespace scope have an internal default relationship.
Consider changing the code later. Perhaps one of the variables should not be const. But at the same time, non-const also changes the default connection. An anonymous namespace will maintain internal communication even after such a change. In other words, the anon namespace shares the problems associated with constant and communication. Whether this is good depends on the context.
Note that the same can be achieved using the static . Since this has the same effect as the anon namespace, the choice is mostly aesthetic and therefore opinion based.
The argument for using anon namespaces instead of static may be consistent. You cannot define types internally linked to static . Since some internal characters (types) cannot be defined outside of the anonymous namespace, you may have an agreement to define all the internal characters in the anonymous namespace. Of course, such a convention would - as a rule, conventions - be a matter of taste.
Your second counter argument seems to argue against a difference that doesn't exist. An anonymous namespace has no meaning to be called hidden within the scope.
source share