title: Acces private static member variable in namespace from another class C++
body: <p>I have a problem. In the following example, there is a static private member variable called <code>private_b</code> of class <code>A</code> inside namespace <code>a</code>. And then I'm trying to access that variable from class <code>B</code>, which I have declared to be a <code>friend</code> of class <code>A</code>, but it doesn't work, with a compile error from GCC:</p>
  <blockquote>
  <p>error: ‘B* a::A::private_b’ is private within this context</p>
  </blockquote>
  <pre><code>class B;
  
  namespace a {
      class A {
      private:
          static B* private_b;
  
          friend class B;
      };
  
      B* A::private_b = nullptr;
  }
  
  class B {
  public:
      void foo() {
          B* foo = a::A::private_b;  // Error here
      }
  };
  </code></pre>
  <p>I don't understand why I can't access it, and how to get around this problem. I really want class <code>A</code> to be inside that namespace, and class <code>B</code> doesn't make sense to be inside that namespace. I searched for this on the internet, but couldn't find this exact case, or couldn't find a solution for this case.</p>