I am getting an Undefined symbols for architecture x86_64 error but I'm not sure why. I am making a stack data type using linked lists and templates.
StackLinkedList.h
#ifndef __StackLinkedList__StackLinkedList__
#define __StackLinkedList__StackLinkedList__
#include <iostream>
using namespace std;
#endif /* defined(__StackLinkedList__StackLinkedList__) */
template <class Item>
class StackLinkedList {
public:
StackLinkedList();
void push(Item p);
private:
StackLinkedList<Item>* node;
Item data;
};
StackLinkedList.cpp
#include "StackLinkedList.h"
template <class Item>
StackLinkedList<Item>::StackLinkedList() {
node = NULL;
}
template <class Item>
void StackLinkedList<Item>::push(Item p) {
if(node == NULL) {
StackLinkedList<Item>* nextNode;
nextNode->data = p;
node = nextNode;
}else {
node->push(p);
}
}
main.cpp
#include "StackLinkedList.h"
int main() {
StackLinkedList<int>* stack;
stack->push(2);
}
Error details:
Undefined symbols for architecture x86_64:
"StackLinkedList<int>::push(int)", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I am using Xcode 6.1.