title: Is it possible to declare a friend function as static?
body: <p>Here is some C++ example code that compiles and works fine:</p>
  
  <pre><code>class A
  {
  public:
     A() {/* empty */}
  
  private:
     friend void IncrementValue(A &amp;);
     int value;
  };
  
  void IncrementValue(A &amp; a)
  {
     a.value++;
  }   
  
  int main(int, char **)
  {
     A a;
     IncrementValue(a);
     return 0;
  }
  </code></pre>
  
  <p>What I would like to do, however, is declare IncrementValue() as static, so that it can't be seen or called from another compilation unit:</p>
  
  <pre><code>static void IncrementValue(A &amp; a)
  {
      a.value++;
  }
  </code></pre>
  
  <p>Doing that, however, gives me a compile error:</p>
  
  <pre><code>temp.cpp: In function ‘void IncrementValue(A&amp;)’:
  temp.cpp:12: error: ‘void IncrementValue(A&amp;)’ was declared ‘extern’ and later ‘static’
  temp.cpp:8: error: previous declaration of ‘void IncrementValue(A&amp;)’
  </code></pre>
  
  <p>... and changing the friend declaration to match doesn't help:</p>
  
  <pre><code>friend static void IncrementValue(A &amp;);
  </code></pre>
  
  <p>... as it gives this error: </p>
  
  <pre><code>temp.cpp:8: error: storage class specifiers invalid in friend function declarations
  </code></pre>
  
  <p>My question is, is there any way in C++ to have a (non-method) friend function that is declared static?</p>