title: operator << friend function and templates
body: <p>This is my code:</p>
  
  <p>mov.h</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  template&lt; class T&gt;
  class Movie {
  public:
      Movie(T in) {
          a = in;
      }
  
      friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const Movie&lt;T&gt;&amp; movie);
  private:
      T a;
  };
  
  template&lt;class T&gt;
  std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const Movie&lt;T&gt;&amp; movie) {
      return os;
  }
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre><code>#include "mov.h"
  
  int main() {
      Movie&lt;int&gt; movie1(1);
  
      std::cout &lt;&lt; movie1 &lt;&lt; std::endl;
  
      return 0;
  }
  </code></pre>
  
  <p>I try to compile this code, and I get the error:</p>
  
  <pre><code>Error 1 error LNK2019: unresolved external symbol "class std::basic_ostream&lt;char,struct std::char_traits&lt;char&gt; &gt; &amp; __cdecl operator&lt;&lt;(class std::basic_ostream&lt;char,struct std::char_traits&lt;char&gt; &gt; &amp;,class Movie&lt;int&gt; const &amp;)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@ABV?$Movie@H@@@Z) referenced in function _main    c:\Users\Adi\documents\visual studio 2013\Projects\bdika01\bdika01\main.obj bdika01
  Error   2   error LNK1120: 1 unresolved externals   c:\users\adi\documents\visual studio 2013\Projects\bdika01\Debug\bdika01.exe    1   1   bdika01
  </code></pre>
  
  <p>If I try the code inline like this it's okay:</p>
  
  <p>mov.h</p>
  
  <pre><code> #include &lt;iostream&gt;
  
   template&lt;class T&gt;
   class Movie {
   public:
       Movie(T in) {
           a = in;
      }
  
      friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const Movie&lt;T&gt;&amp; movie){
          return os;
      }
  private:
      T a;
  };
  </code></pre>
  
  <p>What can I do if I want to separate the defination and declaration?</p>
  
  <p>Thanks.</p>