I've been trying to use template to implement stack. And my question is how do I use the variables from the parent class in this situation?
In this case my compile error is: 'top, a, size' was not declared in this scope.
template<class T>
class buffer
{
public:
T *a;
int top,i,size;
};
template<class T>
class Queue: public buffer<T>
{
public:
Queue(int siz)
{
a=new T[siz];
size=siz;
top=-1;
}
void push(T ele)
{
if(top!=size-1){a[++top]=ele;}
}
T pop()
{
return(a[top--]);
}
void print()
{
for(i=0;i<top;i++)
cout<<" "<<a[i];
cout<<endl;
}
};