Is ADL the only way to call a friend inline function?

后端 未结 3 888
粉色の甜心
粉色の甜心 2020-12-15 04:49

Let us define f, as a friend function of S, inside the declaration of S:

struct S
{
    friend void f() {}
};
<         


        
3条回答
  •  孤城傲影
    2020-12-15 05:08

    The name f is declared in a friend declaration, even it becomes the member of the namespace which contains S, but it's not visible for name lookup, unless it's redeclared at namespace scope. If not, it could be found only by ADL.

    Names introduced by friend declarations within a non-local class X become members of the innermost enclosing namespace of X, but they do not become visible to ordinary name lookup (neither unqualified nor qualified) unless a matching declaration is provided at namespace scope, either before or after the class definition. Such name may be found through ADL which considers both namespaces and classes.

提交回复
热议问题