templates giving me problems
Hi, I made a stack class for myself for ints, now want to template it, but I get wierd syntax errors, but I can't see whats wrong with it.
Code:
struct Node;
typedef Node* NodePtr;
template<class T>
class List
{
public:
List();
void Push(T i); // Pushes i onto stack
T Pop(); // Pops top element from stack
int IsEmpty(); // returns 1 if empty; 0 if not empty;
private:
struct Node
{
T Item;
NodePtr Next;
};
NodePtr Head;
};
List::List()
{
Head = 0;
}
template<class T>
void List<T>::Push(T i) // Pushes i onto stack
{
NodePtr tmp,curr;
//create new node and store integer
tmp = new Node;
tmp->Item = i;
tmp->Next = 0;
//add to top of stack if not empty
if(Head != 0)
{
curr = Head;
while(curr->Next)
curr = curr->Next;
curr->Next = tmp;
}
else
Head = tmp;
}
template<class T>
T List<T>::Pop() // Pops top element from stack
{
T tmp;
if(Head == 0) //nothing to pop!
return 0;
tmp = Head->Item;
Head = Head->Next;
return tmp;
}
int List::IsEmpty() // returns 1 if empty; 0 if not empty;
{
if(Head == 0)
return 1;
return 0;
}