title: How do you declare the friend of a generic class outside of the class decleration?
body: <p>The following code works, but i would like to move ostream&amp; operator&lt;&lt; outside of the class declearation as i have with hash::operator[].</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;map&gt;
  
  using namespace std;
  
  template &lt;class T&gt;
  class hash {
    private:
      map&lt;string, T&gt; _map;
    public:
      T&amp; operator[] (string x);
      friend ostream&amp; operator&lt;&lt;(ostream&amp; out, const hash&lt;T&gt; &amp;rhs) { return out &lt;&lt; "test"; }
  };
  
  template &lt;class T&gt;
  T &amp; hash&lt;T&gt;::operator[](string x) {
    return _map[x];
  }
  
  int main () {
    hash&lt;int&gt; myobject;
    myobject["a"] = 1;
    cout &lt;&lt; myobject["a"] &lt;&lt; endl;
    cout &lt;&lt; myobject &lt;&lt; endl;
    return 0;
  }
  </code></pre>
  
  <p>I have tried:</p>
  
  <pre><code>template &lt;class T&gt;
  ostream&amp; operator&lt;&lt;(...) {
    return out &lt;&lt; "test";
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>ostream&amp; operator&lt;&lt;(...) {
    return out &lt;&lt; "test";
  }
  </code></pre>
  
  <p>as well as a few other combinations to no avail.</p>