title: Why getting linker error with vector?
body: <p>I have for homework to write my own abstract class Vector. I make some of the code, but when I try to compile it I have error. This is the code:</p>
  
  <p><em><strong>vector.hh</em></strong>:</p>
  
  <pre><code>#ifndef VECTOR__HH__
  #define VECTOR__HH_
  
  template&lt;class T&gt; class Vector {
      int capacity_;
      int size_;
      T* buffer_;
  
      void ensure_capacity(unsigned size);
  
  public:
      Vector(int capacity=10) 
        : capacity_(capacity), size_(0), buffer_(new T[capacity])
      { }
  
      ~Vector() {
          delete []buffer_;
      }
  
      int size() const {
          return size_;
      }
  
      bool empty() const {
          return size_ == 0;
      }
  
      T&amp; operator[](int n) {
          return buffer_[n];
      }
  
      const T&amp; operator[](int n) const {
          return buffer_[n];
      }
  
      void clear() {
          // TODO
      }
  
      int capacity() const {
          return capacity_;
      }
  
      T&amp; front() {
          return buffer_[0];
      }
  
      const T&amp; front() const {
          return buffer_[0];
      }
  
      T&amp; back() {
          return buffer_[size_-1];
      }
  
      const T&amp; back() const {
          return buffer_[size_-1];
      }
  
      void push_back(const T&amp; value);
  };
  #endif
  </code></pre>
  
  <p><em><strong>vector.cc</em></strong>:</p>
  
  <pre><code>#include "vector.hh"
  
  template&lt;class T&gt; 
  void Vector&lt;T&gt;::ensure_capacity(unsigned size) {
      if(capacity_&gt;size+1) {
          return;
      } 
  
      capacity_ = capacity_ ==0?1:capacity_;
  
      while(capacity_&lt;size+1) {
          capacity_*=2;
      }
  
      T* old_buffer = buffer_;
      buffer_ = new T[capacity_];
      memcpy(buffer_, old_buffer, sizeof(T)*size_);
  
      delete [] old_buffer;
  }
  
  template&lt;class T&gt;
  void Vector&lt;T&gt;::push_back(const T&amp; value) {
      ensure_capacity(size()+1);
  
      buffer_[size_] = value;
      size_++;
      buffer_[size_] = '/0';
  }
  </code></pre>
  
  <p><em><strong>main.cc</em></strong>:</p>
  
  <pre><code>#include "vector.hh"
  #include &lt;iostream&gt;
  using namespace std;
  
  int main(int argc, char* argv[]) {
      Vector&lt;int&gt; v(2);
      v.push_back(10);
  
      cout &lt;&lt; v[0];
  
      return 0;
  }
  </code></pre>
  
  <p>And error is:</p>
  
  <blockquote>
    <p>g++ -c -o main.o main.cc
    <br/>g++ -Wall -g vector.o main.o -o hw02vector
    <br/>main.o: In function <code>'main'</code>:
    <br/>main.cc:(.text+0x37): undefined reference to <code>'Vector&lt;int&gt;::push_back(int const&amp;)'</code>
    <br/>collect2: ld returned 1 exit status
    <br/>make: <em>*</em> [hw02vector] Error 1</p>
  </blockquote>