title: C++ template/ostream operator question
body: <p>trying to get the operator to work, but throwing me bunch of errors:</p>
  
  <p>my header file</p>
  
  <pre><code>template &lt;unsigned short n&gt;
  class Vector {
  public:
      std::vector&lt;float&gt; coords;
  
      Vector();
      Vector(std::vector&lt;float&gt; crds);
      friend std::ostream&amp; operator &lt;&lt;(std::ostream&amp; out, const Vector&amp; v);
  };
  
  template &lt;unsigned short n&gt;
  Vector&lt;n&gt;::Vector() {
  coords.assign(n, 0.0);
  }
  
  template &lt;unsigned short n&gt;
  std::ostream&amp; operator&lt;&lt;(std::ostream&amp; out, const Vector&lt;n&gt;&amp; v) {
  out &lt;&lt; "(" &lt;&lt; v.coords[1] &lt;&lt; " - " &lt;&lt; v.coords[2] &lt;&lt; ")";
  return out;
  }
  </code></pre>
  
  <p>test file</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "vector.h"
  using namespace std;
  
  int main() {
  Vector&lt;3&gt; toomas;
  cout &lt;&lt; toomas;
  
  }
  </code></pre>
  
  <p>error:</p>
  
  <p>C:\CodeBlocks\kool\praks3\vector.h|14|warning: friend declaration 'std::ostream&amp; operator&lt;&lt;(std::ostream&amp;, const Vector&amp;)' declares a non-template function|</p>
  
  <p>C:\CodeBlocks\kool\praks3\vector.h|14|note: (if this is not what you intended, make sure the function template has already been declared and add &lt;> after the function name here) |</p>
  
  <p>obj\Debug\test.o||In function `main':|</p>
  
  <p>C:\CodeBlocks\kool\praks3\test.cpp|8|undefined reference to `operator&lt;&lt;(std::ostream&amp;, Vector&lt;(unsigned short)3> const&amp;)'|</p>