Oct 10, 2011 at 4:19am UTC
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 Oct 10, 2011 at 4:30am UTC
Oct 10, 2011 at 10:53am UTC
Please put your code inside [CODE] tag .
it is hard to read your code this way.
Oct 10, 2011 at 10:40pm UTC
Thanks so much @sbonnalc.
@ThangDo thanks for the notice but if your not going to help don't bother replying.