Trouble using templates! Please help!

So I am trying to create a HashTable class and a HashEntry class that use templates.

Currently I am working on the HashEntry. The .h file is as follow:

#ifndef HASHENTRY_H
#define HASHENTRY_H
#include <iostream>

using namespace std;

template <class Data>
class HashEntry
{
private:
Data data;
int key;

public:
HashEntry();
Data getData();
int getKey();
void setKey(int i);
void setData(Data _data);
~HashEntry();
};

#endif // HASHENTRY_H

The .cpp file is:

#include "hashentry.h"

template <class Data>
HashEntry<Data>::HashEntry(){
data = NULL;
key = 0;
}

template <class Data>
Data HashEntry<Data>::getData(){
return data;
}

template <class Data>
int HashEntry<Data>::getKey(){
return key;
}

template <class Data>
void HashEntry<Data>::setKey(int i){
key = i;
}

template <class Data>
void HashEntry<Data>::setData(Data _data){
data = _data;
}

template <class Data>
HashEntry<Data>::~HashEntry(){}

Now I try to test the class using this:

void main(){
HashEntry<int>* entry1 = new HasHEntry<int>();
entry1->setKey(8);
entry1->setData(8);
}

When I try it i get a "LNK 2019: unresolved external symbol" a number of times on each of the calls. I'm not comfortable with c++ yet and I am trying to learn. That is why I am doing all this.
Last edited on
Templates needs to be defined and implemented in the header file.
If you put the implementation in a separate .cpp file, it doesn't work at link time.

You can check the template documentation here: http://cplusplus.com/doc/tutorial/templates/
It's just at the end of the page.

Cheers.
Please put your code inside [CODE] tag .

it is hard to read your code this way.
Thanks so much @sbonnalc.

@ThangDo thanks for the notice but if your not going to help don't bother replying.
Topic archived. No new replies allowed.