#ifndef NUMSTACK_HPP_INCLUDED
#define NUMSTACK_HPP_INCLUDED
template <class T> class NumStack
{
private:
T *stackArray; // Pointer to the stack array
T stackSize; // The stack size
T top; // Indicates the top of the stack
public:
// Constructor
NumStack(T);
// Copy constructor
NumStack(const NumStack &);
// Destructor
~NumStack();
// Stack operations
void push(T);
void pop(T &);
bool isFull() const;
bool isEmpty() const;
};
#endif // NUMSTACK_HPP_INCLUDED
I do have a couple other errors. In the Stack<T> constructor I'm getting the error
"class 'Stack<T> does not have any field named 'NumStack'" In main it also says that I'm missing template arguments before 'stack'.
Here is my main
In main it also says that I'm missing template arguments before 'stack'.
you need to decide whether the derived class is also going to be a template class or not. At the moment the way you've laid out Stack in it's header file seems to suggest that it is a template class while in main() Stack is represented as a non-template class i.e. it is derived from a particular instantiation of NumStack<T>
if you want only NumStack to be template but not Stack it'd be something like:
1 2
template <typename T> class NumStack{};
class Stack : public NumStack<int>{};//Stack derived from NumStack<int> for e.g.
Also NumStack is missing the template parameter here: template <class T> class Stack : public NumStack // should be NumStack<T>
As for the other error message: "class 'Stack<T> does not have any field named 'NumStack'"
this is entirely reasonable given that NumStack<T> is expected to be a base for Stack(template or otherwise)
Both classes need to be templates. template <class T> class Stack : public NumStack<T>
I added NumStack<T>, but it still tells me that I'm missing template arguments.