I am trying to make a simple linked list, and I came across a LNK2019 when I started to add code to my main function. It was compiling before, but when I added code to my main, I got several errors. I have all my header files included in my main CPP file, and I checked for circular includes. I haven't used C++ in a while, so sorry if this seems obvious. I went with the precompiled headers option when I made the project, if that means anything. What am I messing up?
Errors:
1>RandomCPP.obj : error LNK2019: unresolved external symbol "public: __thiscall List<int>::List<int>(void)" (??0?$List@H@@QAE@XZ) referenced in function _wmain
1>RandomCPP.obj : error LNK2019: unresolved external symbol "public: __thiscall List<int>::~List<int>(void)" (??1?$List@H@@QAE@XZ) referenced in function _wmain
1>RandomCPP.obj : error LNK2019: unresolved external symbol "public: void __thiscall List<int>::add(int const &)" (?add@?$List@H@@QAEXABH@Z) referenced in function _wmain
1>RandomCPP.obj : error LNK2019: unresolved external symbol "public: int * __thiscall List<int>::get(int)const " (?get@?$List@H@@QBEPAHH@Z) referenced in function _wmain
List.h:
#pragma once
#include "ListNode.h"
template<class T> class ListNode;
template<class T>
class List
{
public:
List<T>();
~List<T>();
void add(const T&);
void insert(int, const T&);
void clear();
bool isEmpty() const;
T* get(const int) const;
int getLength() const;
void foreach(void(*foo)(T)) const;
T* operator[](const int index) const;
private:
ListNode<T>* firstElement;
ListNode<T>* lastElement;
//Utility
ListNode<T>* getNewNode(const T&);
ListNode<T>* getNode(int index) const;
};
ListNode.h:
#pragma once
template<class T> class List;
template <class T>
class ListNode
{
friend class List < T > ;
public:
ListNode(const T& data);
~ListNode();
T getData() const;
private:
T data;
ListNode<T> *nextPtr;
};
RandomCPP.cpp (Main File):
#include "stdafx.h"
#include "List.h"
#include "ListNode.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
List<int> values = List<int>();
values.add(0);
values.add(1);
values.add(2);
values.add(3);
values.add(4);
cout << values.get(0) << endl
<< values.get(1) << endl
<< values.get(2) << endl
<< values.get(3) << endl
<< values.get(4) << endl << endl;
system("pause");
return 0;
}
stdafx.h:
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#include <iostream>
I have a List.cpp file and a ListNode.cpp file, each of which contain the definitions of the class declared in the corresponding .h file, and nothing else. The stdafx.cpp file is empty except an include of stdafx.h.