0

I've built a LinkedList with template but compiling returns undefined reference to the constructor and destructor and will not compile

From driver:

LinkedList<int> myList;

From .cpp

template <class itemType>
LinkedList<itemType>::LinkedList()

{
    size = 0;
    head = NULL;
}

driver.cpp:(.text+0x20): undefined reference to LinkedList<int>::LinkedList()' driver.cpp:(.text+0x31): undefined reference toLinkedList::~LinkedList()'

Mellow
  • 1
  • 1
  • 2
  • What is the type of `size` and `head`? – wally Dec 01 '17 at 22:17
  • Could you post the types of the other variables? – Jake Freeman Dec 01 '17 at 22:17
  • The implementations of any *class template* or *function template* is supposed to be visible to the compiler at point of instatiation, however, if it's not visible at point of instatiation, then it should have been explicitly instatiated in another translation unit that you link with, else you'll get this error. See [Why can templates only be implemented in header](https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file) – WhiZTiM Dec 01 '17 at 22:19
  • Edit.. Ended up deleting #include the .h and subbed #include the cpp and it worked?? – Mellow Dec 01 '17 at 22:39

0 Answers0