I wanted to use templates to make more general data structures for example a stack by linking node* objects. But once I used the template the node class is no longer identified, the compiler says:
Error GCC template class Node’ declared here Error GCC invalid use of template-name ‘Node’ without an argument list
And there's my code on the header file so far:
#ifndef STACK_HPP
#define STACK_HPP
template <class Object>
class Node{
friend class Stack;
private:
Object data;
Node* next;
public:
Node(Object d);
Node();
};
template <class Object>
class Stack{
private:
Node* top;
int size;
bool isEmpty();
public:
Stack();
~Stack();
void Push(Object d);
Object Pop();
Object Spy();
};
#endif
The compiler will not attempt to infer what
Node
might be in yourStack
class, it's just a template. You need to provide a concrete class, as inNode<Object>
.