title: friend declaration declares a non-template function
body: <p>I have a base Class akin to the code below.  I'm attempting to overload &lt;&lt; to use with cout.
  However, g++ is saying:</p>
  
  <pre><code>base.h:24: warning: friend declaration ‘std::ostream&amp; operator&lt;&lt;(std::ostream&amp;, Base&lt;T&gt;*)’ declares a non-template function
  base.h:24: warning: (if this is not what you intended, make sure the function template has already been declared and add &lt;&gt; after the function name here) -Wno-non-template-friend disables this warning
  </code></pre>
  
  <p>I've tried adding &lt;> after &lt;&lt; in the class declaration / prototype.  However, then I get it <code>does not match any template declaration</code>.  I've been attempting to have the operator definition fully templated (which I want), but I've only been able to get it to work with the following code, with the operator manually instantiated.</p>
  
  <p>base.h</p>
  
  <pre><code>template &lt;typename T&gt;
  class Base {
    public:
      friend ostream&amp; operator &lt;&lt; (ostream &amp;out, Base&lt;T&gt; *e);
  };
  </code></pre>
  
  <p>base.cpp</p>
  
  <pre><code>ostream&amp; operator&lt;&lt; (ostream &amp;out, Base&lt;int&gt; *e) {
      out &lt;&lt; e-&gt;data;
  return out;
  }
  </code></pre>
  
  <p>I want to just have this or similar in the header, base.h:</p>
  
  <pre><code>template &lt;typename T&gt;
  class Base {
    public:
      friend ostream&amp; operator &lt;&lt; (ostream &amp;out, Base&lt;T&gt; *e);
  };
  
  template &lt;typename T&gt;
  ostream&amp; operator&lt;&lt; (ostream &amp;out, Base&lt;T&gt; *e) {
      out &lt;&lt; e-&gt;data;
  return out;
  }
  </code></pre>
  
  <p>I've read elsewhere online that putting &lt;> between &lt;&lt; and () in the prototype should fix this, but it doesn't.  Can I get this into a single function template?</p>