How can I declare a friend function in a namespace that takes an inner class as a parameter?
Consider this code:

    namespace foo {}
    
    class A
    {
       class B
       {
       };
    
       friend int foo::bar( B& );
    };
    
    namespace foo
    {
       int bar( A::B& )
       {
       }
    }

G++ 4.4.3 tells me:

> friendfun-innerclass.cpp:21: error: 'int foo::bar(A::B&)' should have
> been declared inside 'foo'

But I can't declare:

    namespace foo
    {
       int bar( A::B& );
    }

before the class A definition because A::B hasn't been declared.  And I can't declare  "class A::B" obviously, to declare class B I have to give the definition of class A, and as far as I know the "friend" declarations have to be inside the definition of class A.

What's strange to me is that if I take function "bar()" out of namespace foo everything works fine.  It seems counterintuitive to me that having a function inside a namespace or not inside a namespace changes whether the compiler will accept a friend function declaration in the class.  

Does anybody know of a way to proprerly structure all the declarations and such to get this to work?

How can I declare a friend function in a namespace that takes an inner class as a parameter?
===

Consider this code:

    namespace foo {}
    
    class A
    {
       class B
       {
       };
    
       friend int foo::bar( B& );
    };
    
    namespace foo
    {
       int bar( A::B& )
       {
       }
    }

G++ 4.4.3 tells me:

> friendfun-innerclass.cpp:21: error: 'int foo::bar(A::B&)' should have
> been declared inside 'foo'

But I can't declare:

    namespace foo
    {
       int bar( A::B& );
    }

before the class A definition because A::B hasn't been declared.  And I can't declare  "class A::B" obviously, to declare class B I have to give the definition of class A, and as far as I know the "friend" declarations have to be inside the definition of class A.

What's strange to me is that if I take function "bar()" out of namespace foo everything works fine.  It seems counterintuitive to me that having a function inside a namespace or not inside a namespace changes whether the compiler will accept a friend function declaration in the class.  

Does anybody know of a way to proprerly structure all the declarations and such to get this to work?
