title: C++ class template undefined reference to function
body: <p>I keep getting undefined reference when i call the two functions from my template class "add" and "greater" in my main function.</p>
  
  <p>So, i have:
  number.h</p>
  
  <pre><code>#ifndef NUMBER_H
  #define NUMBER_H
  
  template &lt;class T&gt;
  class number {
  public:
      T x;
      T y;
  
      number (int a, int b){
          x=a; y=b;}
      int add (T&amp;);
      T greater ();
  };
  
  #endif
  </code></pre>
  
  <p>number.cpp</p>
  
  <pre><code>#include "number.h"
  
  template &lt;class T&gt;
  int number&lt;T&gt;::add (T&amp; rezAdd){
      rezAdd = x+y;
      return 1;
  }
  
  template &lt;class T&gt;
  T number&lt;T&gt;::greater (){
          return x&gt;y? x : y;
  }
  </code></pre>
  
  <p>And my main file is: resolver.cpp</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include "number.h"
  
  int main (int argc, char **argv) {
      int aux;
      number&lt;int&gt; c(3,5);
  
      c.add(aux);
      printf ("number added [%d]\n", c.add(aux));
      printf ("greater number: [%d]\n", c.greater());
  
      return 0;
  }
  </code></pre>
  
  <p>The errors that i keep getting are:</p>
  
  <pre><code>g++ -Wall -o tema1 resolver.cpp number.cpp
  /tmp/ccX483J4.o: In function `main':
  resolver.cpp:(.text+0x34): undefined reference to `number&lt;int&gt;::add(int&amp;)'
  resolver.cpp:(.text+0x47): undefined reference to `number&lt;int&gt;::add(int&amp;)'
  resolver.cpp:(.text+0x64): undefined reference to `number&lt;int&gt;::greater()'
  collect2: ld returned 1 exit status
  make: *** [all] Error 1
  </code></pre>
  
  <p>Thanks for the help in advance!</p>