Hello All
I have used templates all within a header file for a while now, but when I try and separate the code into .h and .cpp files it breaks :(
It all worked fine when all the hash class functions were all in the header file within the class itself.
I really need to have this in separate header and source files, due to I plan to put this in a library with other classes, and if it all has to be in the header file then it’s not worth having the library.
Anyone know how to resolve this, I have looked for the last few hours, looking at example code and trying how they did it, but it still fails to compile :(
What am I doing wrong ?
Oh btw I am using Visual Studio 2003 if that helps.
// Error:
storage.obj : error LNK2019: unresolved external symbol "public: void __thiscall HashTable<int,class Player>::Initialize(int)"
(?Initialize@?$HashTable@HVPlayer@@@@QAEXH@Z) referenced in function "public: __thiscall Storage::Storage(void)" (??0Storage@@QAE@XZ)
I have removed the bulk of the code or the post would of been very long.
Hash Header File
// hash.h
template<typename KeyType, typename DataType> class HashTable
{
public:
...
void Initialize(int p_size);
...
};
Hash Source File
// hash.cpp
#include "hash.h"
template<typename KeyType, typename DataType>
void HashTable<KeyType, DataType>::Initialize(int p_size)
{
...
}
Storage Header File
// storage.h
class Storage
{
public:
HashTable<int, class Player> playerlist;
HashEntry<int, class Player>* player;
Storage();
...
};
Storage Source File
// storage.cpp
#include "hash.h"
#include "storage.h"
Storage::Storage()
{
playerlist.Initialize(MAX_PLAYER_CELL);
}
Thanks in advance
Paul Kirby