friend functions of a class inside a namespace

后端 未结 3 1673
别那么骄傲
别那么骄傲 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:36

    1) because function f is declared and defined outside of the current namespace. If you moved the definition of your class into the same namespace as the function whether global or otherwise you wouldn't need to.

    2) you always need to declare a function before it is referenced. Your class references the function with the friend statement.

提交回复
热议问题