title: Is it possible to friend a class in an anonymous namespace in C++?
body: <p>I am porting code from Java to c++ and I'd like to replicate some anonymous functionalities.</p>
  
  <p>In file A.h I have :</p>
  
  <pre><code>class A
  {
  private:
    int a;
  
    class AnonClass;
    friend class AnonClass;
  };
  </code></pre>
  
  <p>In file A.cpp I have :</p>
  
  <pre><code>namespace
  {
    class AnonClass
    {
    public:
      AnonClass(A* parent)
      {
        parent-&gt;a = 0; // This doesn't work, a is not accessible
      }
    }
  }
  </code></pre>
  
  <p>Is it possible to friend a class in an anonymous namespace in C++?</p>
  
  <p>In Java you can declare anonymous classes so it would be very similar. Also it would not expose AnonClass to clients of A.h</p>