C++ language does not allow you to use qualified names (like ::A
) in friend declarations, unless these qualified names refer to previously declared entities. Actually, this rule is applied virtualy everywhere, not only in friend declarations: qualified names have to refer to previously declared entities.
In your case you used qualified name ::A
in friend declaration friend struct ::A
. For that to work, struct A
from global namespace has to be known to the compiler beforehand. In your case A
is not declared at that point, which makes friend struct ::A
declaration ill-formed. It should not even compile by formal rules of the language.
If your compiler accepts this, you have to consult your compiler documentatuion to figure out what it means. I suspect that friend struct ::A
for unknown ::A
is interpreted as equivalent to friend struct A
, i.e. it declares _detail::A
as friend.
If you make a forward declaration struct A;
before declaring namespace _detail
, it might make it work as intended.