Reputation: 75
I am trying to use a template class in the stack with an array. The code is running fine but when I added template class, the code generates an error. This is the error message. Error: 'stack' is not a class, namespace, or enumeration.
template<class T>
class stack{
private:
int top;
T a[MAX_value];
public:
stack():top (-1){}
void push(T element);
T pop();
bool isEmpty();
void display();
void getTop();
};
void stack::push(T element){
.......
}
T stack::pop(){
....
}
I expected to get an integer output if I declare the stack input as integer or double.
stack<int> s, or stack<double> s.
Upvotes: 0
Views: 183
Reputation: 52611
The correct syntax for defining a member function for a class template outside the class definition is this:
template <class T>
void stack<T>::push(T element) {...}
Upvotes: 2