Skip to main content
gamedev.net
🔒 Locked 🤖 Godot

Templates question

Started by Rattrap 2 replies 650+ views
Original Post
Rattrap
Rattrap
There is probably just something really stupid wrong with this code.

//  Header File
template <typename T>
class CDoubleLinkList
{
public:
	CDoubleLinkList(void);
	~CDoubleLinkList(void);

protected:

private:

};


//  Cpp File
#include "CDoubleLinkList.h"

template <typename T>
CDoubleLinkList<T>::CDoubleLinkList(void)
{
}

template <typename T>
CDoubleLinkList<T>::~CDoubleLinkList(void)
{
}

Nothing real fancy yet. They don't even do anything yet. But I tried compiling this

#include "CDoubleLinkList.h"

int main(void)
{
	CDoubleLinkList<int> dllTest;
	return 0;
}

and get this back main.obj : error LNK2019: unresolved external symbol "public: __thiscall CDoubleLinkList::~CDoubleLinkList(void)" (??1?$CDoubleLinkList@H@@QAE@XZ) referenced in function _main main.obj : error LNK2019: unresolved external symbol "public: __thiscall CDoubleLinkList::CDoubleLinkList(void)" (??0?$CDoubleLinkList@H@@QAE@XZ) referenced in function _main I have tried looking at various how to template stuff, and I think what I wrote looks correct. I will note I'm using Visual Studio C++ 2005 Express Beta, so it is possibly something wrote with the compiler.
"I can't believe I'm defending logic to a turing machine." - Kent Woolworth [Other Space]
Rattrap
Rattrap
Thanks. I figured it was something stupid.
"I can't believe I'm defending logic to a turing machine." - Kent Woolworth [Other Space]
snk_kid
snk_kid
As partially noted already, it's not exactly true that template code needs to be all in header but they definitely need to be the same translation unit unless your compiler supports the export keyword which nearly none do. If you really wanna sperate your code you can always put definitions into another file (it can have any file extension) and include at the end of the header.

Also note the C++ standard library provides containers and algorithms including a list type known as std::list in header *list*, there-for you should use that if you just want to use a list.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.