I am trying to create a linked list using multiple files but am getting 2 errors
"main.obj : error LNK2019: unresolved external symbol "public: void __thiscall LinkedList<int>::print(void)" (?print@?$LinkedList@H@@QAEXXZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "public: void __thiscall LinkedList<int>::add(int)" (?add@?$LinkedList@H@@QAEXH@Z) referenced in function _main"
I have no idea what I am doing wrong. My syntax seems correct. Please help!
<<<<<<<<< main.cpp >>>>>>>>>>>>>>>>>>>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#include <iostream>
#include <stdlib.h>
#include "LinkedList.h"
using namespace std;
int main() {
int poop;
cout << "HELLO!\n";
LinkedList<int> *list = new LinkedList<int>();
list->add(10);
list->add(20);
list->print();
cin >> poop;
return 0;
}
|
========================================================================
<<<<<<<<<<<<< LinkedList.cpp >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include <iostream>
#include <stdlib.h>
#include "LinkedList.h"
template <class T> void LinkedList<T>::add(T value) {
if (head == NULL) {
head = new Node(value);
tail = head;
}
else {
Node *temp = tail;
tail = new Node(value);
temp->next = tail;
}
}
template <class T> void LinkedList<T>::print() {
Node *curr = head;
while (curr != NULL) {
cout << curr->val << " | ";
curr = curr->next;
}
}
|
=======================================================
<<<<<<<<<<<<<<<< LinkedList.h >>>>>>>>>>>>>>>>>>>>>>>>>>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
template <class T>
class LinkedList {
public:
LinkedList() { head = NULL; tail = NULL; }
//~LinkedList();
void add(T value);
//void remove(T value);
void print();
private:
struct Node {
T val;
Node *next;
Node(T value) { val = value; next = NULL; }
};
Node *head;
Node *tail;
};
#endif
|
=========================================================================