friend functions of a class inside a namespace

后端 未结 3 1822
别那么骄傲
别那么骄傲 2021-01-18 16:50

I\'ve two question about this code bellow:

namespace A { class window; }

void f(A::window);

namespace A
{
    class window
    {
    private:
       int a;         


        
3条回答
  •  南方客
    南方客 (楼主)
    2021-01-18 17:45

    As for 1), your function is not in the namespace, so you must use :: to tell the compiler to search it outside the namespace.

    Otherwise, it will only look for function inside the namespace (that's why they exist). Koenig lookup doesn't apply here, as window class is inside the namespace.

    not too sure about 2) though, but i bet it is related to 1).

提交回复
热议问题