I'm having a problem with creating my own stack class and implementing it in a postfix calculator program I made. I was trying to make the stack.h file, but it keeps telling me stack is not a template
#ifndef STACK_H
#define STACK_H
#include <iostream>
using namespace std;
template <typename T>
class ListNode
{
public:
ListNode();
private:
T value;
ListNode<T> *next;
friend class stack<T>;
};
template <class T>
class stack
{
public:
stack( );
~stack( );
void push(T const&);
void makeEmpty();
bool isEmpty() const;
void pop();
T top();
private:
ListNode<T> *topOfStack;
};
#endif
and here is my implementation:
#include <iostream>
#include "stack.h"
using namespace std;
template<typename T>
ListNode<T>::ListNode(){
next = NULL;
value = NULL;
};
template<typename T>
stack<T>::stack(){
topOfStack = NULL;
};
template<typename T>
stack<T>::~stack(){
makeEmpty();
}
template<typename T>
T stack<T>::top(){
return topOfStack->value;
}
template<typename T>
void stack<T>::pop(){
ListNode<T> *newnode = new ListNode<T>();
topOfStack = topOfStack->next;
delete newnode;
}
template<typename T>
bool stack<T>::isEmpty()const{
return topOfStack==NULL;
}
template<typename T>
void stack<T>::makeEmpty(){
while(!isEmpty()){
pop();
}
}
template<typename T>
void stack<T>::push(T const& x){
ListNode<T> *newnode = new ListNode<T>();
newnode->value = x;
newnode->next = topOfStack;
topOfStack = newnode;
}
int main(){
return 0;
}
This is my first time working with templates so im not sure if its right