namespace N{
inline namespace NS1{
struct A{
friend void FuncA(A){}              //在类内查找的只有友元,因为其他的均为类成员
};
    void FN1(A){}
}
    void FN(NS1::A){}
}
struct B:N::NS1::A{
    friend void FuncB(B){}
};
namespace E{
namespace NS2{
struct C:B{
    friend void FuncC(C){}
};
    void FN2(C){}
    inline namespace NiS2{
        void FiS2(C){}
    }
}
    void FE(NS2::C){}
}
void foo(){
    E::NS2::C s;
    FN2(s);
    FuncC(s);
    FuncB(s);
    FN1(s);
    FuncA(s);
    FN(s);
    FiS2(s);
    //FE(s);    查找不到
}
struct A{
    struct B{
        struct C{
        };
        friend void F(C){}
    };
    friend void F1(B::C){}
};
void foo(){
    A::B::C s;
    F(s);
    //F1(s);
}
namespace N{
    struct E{
        struct A{
            struct B{
            };
        };
        friend void F2(A::B){}
    };
    void F(E::A::B){}
}
void Foo(){
    N::E::A::B s;
    F(s);
    //F2(s);
}template<template<class D>class TY,class ... Ty>
struct T{};
namespace N2{
    struct B;    
}
namespace N3{
    struct N{
        template<class D>
        struct TY;
        friend void F1(T<TY,N2::B>){}
    };
}
namespace N1{
    struct A{
    };
    void F3(T<N3::N::TY,N2::B>){}
}
namespace N2{
    struct B:N1::A{
    };
}
namespace N3{
    template<class D>
    struct N::TY{
        friend void F4(T<TY,N2::B>){}
    };
    void F2(T<N::TY,N2::B>){}
}
void foo(){
    T<N3::N::TY,N2::B> s;
    F1(s);
    F2(s);
    F3(s);
    //F4(s);
}
原文:https://www.cnblogs.com/A001/p/10632133.html