title: Declaring a namespace as a friend of a class
body: <p>I was wondering if there is a way such that we make all functions defined within a specific namespace <code>friend</code> with a class?</p>
  
  <p>In particular, I have a class, for example:</p>
  
  <pre><code>class C {
      private:
          // ...
      public:
          // ...
  
          friend C* B::f1(C*);
          friend C* B::f2(C*);
          friend C* B::f3(C*);
          friend C* B::f4(C*);
          friend C* B::f5(C*);
  };
  </code></pre>
  
  <p>and a namespace <code>B</code> as:</p>
  
  <pre><code>namespace B {
      C* f1(C* x);
      C* f2(C* x);
      C* f3(C* x);
      C* f4(C* x);
      C* f5(C* x);
  };
  </code></pre>
  
  <p>Now, I would prefer to avoid writing 5 lines in the class definition to make all five functions of the namespace <code>B</code> friend with class <code>C</code> and just tell the compiler that all of the functions defined within the namespace <code>B</code> are friends with the class <code>C</code> (i.e. can access its private members).</p>
  
  <p>A quick fix I guess is to change the namespace to a class and define the functions as its static members and then declare the class <code>B</code> as a friend of class <code>C</code>. However, out of curiosity I was wondering if such thing is possible with namespaces as well or not?</p>
  
  <p>Thanks in advance.</p>