VS2012 C++ LKN2019

  • Thread starter Thread starter Blonde Llama
  • Start date Start date
B

Blonde Llama

Guest
I started experimenting with templates, but I ran into an error. I was wondering if the error is in the settings of visual studio or if I made a fundamental flaw in my code. Thanks in advance.


HashTable.cpp

// HashTable v2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <cstdlib>
#include <iostream>
#include <string>

#include "hash.h"

using namespace std;

struct Data{
int a, b;
};

int _tmain(int argc, _TCHAR* argv[])
{
Data data1;
data1.a = 1;
data1.b = 2;
string name1 = "Person";;

HashElem<Data> elem(name1, &data1, nullptr);
cout << elem.name << endl;
cout << elem.data->a << endl;
cin.get();

return 0;
}


hash.h

#include "stdafx.h"
#include <stdlib.h>
#include <iostream>
#include <string>

using namespace std;

#ifndef HASH_H
#define HASH_H

template <class T>
class HashElem;

template <class T>
class HashElem{
// friend class HashTable<T>; //HashTable can access HashElem variables and functions

public:
string name; // name of element
T* data; // reference to T struct/class with data of element
HashElem<T>* next; //next element

public:
HashElem();
HashElem(string name, T* data, HashElem<T>* next);
};

#endif /* HASH_H */

hash.cpp

#include "stdafx.h"

#include <cstdlib>
#include <iostream>
#include <string>

#include "hash.h"

using namespace std;

//HASHELEM

template <class T>
HashElem<T>::HashElem(){
name = "";
data* = nullptr;
next* = nullptr;
}

template <class T>
HashElem<T>::HashElem(string i_name, T* i_data, HashElem<T>* i_next){
name = i_name;
data* = i_data;
next* = i_next;
}


Error:

Error 1 error LNK2019: unresolved external symbol "public: __thiscall HashElem<struct Data>::HashElem<struct Data>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct Data *,class HashElem<struct Data> *)" (??0?$HashElem@UData@@@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAUData@@PAV0@@Z) referenced in function _wmain C:\Users\Jeroen\Documents\Visual Studio 2012\HashTable v2\HashTable v2\HashTable v2.obj HashTable v2

Continue reading...
 
Back
Top