title: Why does a C++ friend class need a forward declaration only in other namespaces?
body: <p>Suppose I have a class <code>F</code> that should be friend to the classes <code>G</code> (in the global namespace) and <code>C</code> (in namespace <code>A</code>).</p>
  
  <ul>
  <li>to be friend to <code>A::C</code>, <code>F</code> must be forward declared.</li>
  <li>to be friend to <code>G</code>, no forward declaration of <code>F</code> is necessary.</li>
  <li>likewise, a class <code>A::BF</code> can be friend to <code>A::C</code> without forward declaration</li>
  </ul>
  
  <p>The following code illustrates this and compiles with GCC 4.5, VC++ 10 and at least with one other compiler.</p>
  
  <pre><code>class G {
      friend class F;
      int g;
  };
  
  // without this forward declaration, F can't be friend to A::C
  class F;
  
  namespace A {
  
  class C {
      friend class ::F;
      friend class BF;
      int c;
  };
  
  class BF {
  public:
      BF() { c.c = 2; }
  private:
      C c;
  };
  
  } // namespace A
  
  class F {
  public:
      F() { g.g = 3; c.c = 2; }
  private:
      G g;
      A::C c;
  };
  
  int main()
  {
      F f;
  }
  </code></pre>
  
  <p>To me this seems inconsistent. Is there a reason for this or is it just a design decision of the standard?</p>