title: Templates and .cpp files
body: <p>I am learning C++ and it hasn't been an enjoyable experience (compared to Java or VBA at least). I have the following code:</p>
  
  <pre><code>//This is in a number.h file
    #pragma once
    template &lt;class T&gt;
    class number{
          public: 
                 T value1, value2, result; 
          public: 
                 T add();
                 number(T value1_in, T value2_in);
    };
  
   //This is in a number.cpp file
     template &lt;class T&gt;
     number&lt;T&gt;::number(T value1_in, T value2_in){
                value1 = value1_in;
                value2 = value2_in;
     }
  
     template &lt;class T&gt;
     T number&lt;T&gt;::add(){
     result = value1 + value2; 
     return result; 
     }
  
   //This is in main.cpp
     #include "number.h"
     #include &lt;iostream&gt;
     using namespace std;
  
     int main(){
         int a = 2, b =3;
  
         number&lt;int&gt; n1(a,b);
         cout &lt;&lt; n1.add();
         system("pause");
         return EXIT_SUCCESS;
    }
  </code></pre>
  
  <p>Which of course gives me an error. Even though I am pretty sure it should work. More specifically I get a linker error. After 3 hours of looking at this I decided to include number.cpp in main.cpp and that magically made it work. What the hell is going on? I thought I only need to include the header file (I wrote a matrix class with a bunch of linear solvers for different algorithms before this and only included header files in the whole project). Is this C++ specific or compiler specific? (I am using Dev-C++ 4.9.9.2 which has Mingw I guess)</p>