title: How do I define friends in global namespace within another C++ namespace?
body: <p>I'd like to define a binary operator on in the global namespace. The operator
  works on a class that is defined in another namespace and the operator should get
  access to the private members of that class. The problem I have is that I don't
  know how to scope that global operator when making it a friend in the class definition.</p>
  
  <p>I tried something like:</p>
  
  <pre><code>namespace NAME
  {
      class A {
          public:
              friend A ::operator * (double lhs, const A&amp; rhs);
          private:
              int private_var;
      };
  }
  
  A operator * (double lhs, const A&amp; rhs)
  {
      double x = rhs.private_var;
      ...
  }
  </code></pre>
  
  <p>The compiler (g++ 4.4) didn't know what to do with it. It seems that the line</p>
  
  <pre><code>friend A ::operator * ()
  </code></pre>
  
  <p>is evaluated as something like (pseudo-code)</p>
  
  <pre><code>(A::operator)
  </code></pre>
  
  <p>instead of </p>
  
  <pre><code>(A) (::operator)
  </code></pre>
  
  <p>If I leave out the :: in the declaration of the operator the compiling works but the operator is then in namespace NAME and not in the global namespace.</p>
  
  <p>How can I qualify the global namespace in such a situation?</p>