Reputation: 269
Ok, without including the whole codebase...
#ifdef KIT_EXPORTS
#define KIT_API __declspec(dllexport)
#define EXP_TEMPLATE
#else
#define KIT_API __declspec(dllimport)
#define EXP_TEMPLATE extern
#endif
#ifndef KIT_LINKED_LIST_H
#define KIT_LINKED_LIST_H
#includes ...
namespace Kit
{
template <class tmplt>
class KIT_API KitLinkedList
{
private:
...
public:
KitLinkedList()
{
...
}
KitLinkedList(tmplt obj)
{
...
}
KitLinkedList(const KitLinkedList& other)
{
...
}
~KitLinkedList()
{
...
}
void PushBack(tmplt obj)
{
KitLinkedListNode<tmplt>* addedNode = new KitLinkedListNode<tmplt>(obj);
tail->nextNode = addedNode;
tail = addedNode;
count++;
}
uint64_t Count()
{
return count;
}
KitLinkedListIterator<tmplt> GetIterator()
{
return KitLinkedListIterator<tmplt>(root->nextNode);
}
... some other happy functions live here
};
}
My non-dll code:
KitLinkedList<KitString> savedGameList = saveSet.ListSavedGames();
savedGameList.PushBack(KitString("blah"));
if (savedGameList.Count() > 0)
{
}
savedGameList.Count() causes LNK2019, but the pushback() and getiterator() don't.
Upvotes: 0
Views: 90
Reputation: 269
The correct answer is that the template class isn't dependent on the dll, since everything it needs is in the header. So KIT_API should be removed.
Upvotes: 1
Reputation: 269
Ok, this got me building, but I don't know why it works:
Declare the function as:
template <class tmplt>
uint64_t Count()
{
return count;
}
And call it thus:
if (savedGameList.Count<KitString>() > 0)
Apparently the compiler doesn't see the function because it doesn't carry the templated type (even though it is within the scope of the class declaration)
Upvotes: 0