Q:

failing to invoke template class, c++

I've defined a template class like so (providing .hpp file):
#ifndef PERSOANLVEC_H_
#define PERSOANLVEC_H_

#include <vector>

using namespace std;

template<class T, class PrnT> class PersoanlVec {
public:
    PersoanlVec();
    ~PersoanlVec();
    void push_back(T t);
    void erase(int index);
    PersoanlVec& operator[](int index);
    const PersoanlVec& operator[](int index) const;
    void print() const;
    size_t size();
private:
    vector<T> _vector;
};

#endif /* PERSOANLVEC_H_ */

Now, everything compiles ok with this class. When I try to use it I get
undefined reference to PersoanlVec<Person, Person>::PersoanlVec()'.
Here's where I call it:
#include "Person.h"
#include "PersoanlVec.hpp"
#include <cstdlib>

int main(void)
{
    Person p1("yotam");
    Person p2("yaara");
    PersoanlVec<Person,Person> *a = new PersoanlVec<Person,Person>(); //<---ERROR HERE
    return EXIT_SUCCESS;
}

This is my first try with templates, its not very clear for me obviously. I DO have a constructor with no parameters, Any ideas?
Thanks!

A:

Do you have the content of your constructor and functions in a .cpp file? If yes, there's your problem. Put them in the header file, possible just inline in the class itself:
template<class T, class PrnT> class PersoanlVec {
public:
    PersoanlVec(){
      // code here...
    }

    ~PersoanlVec(){
      // code here...
    }

    void push_back(T t){
      // code here...
    }

    void erase(int index){
      // code here...
    }

    PersoanlVec& operator[](int index){
      // code here...
    }

    const PersoanlVec& operator[](int index) const{
      // code here...
    }

    void print() const{
      // code here...
    }

    size_t size(){
      // code here...
    }

private:
    vector<T> _vector;
};

For the reason, have a look here.

