Reputation: 45
stack.h
template <class DataType>
class Stack {
private:
int * topPtr;
public:
Stack(); //constructor; initializes top to nullptr
void push(); //adds a node
void pop(); //removes most recently added node
};
And stack.cpp thus far:
#include "stack.h"
//using namespace std;
template <class DataType>
Stack::Stack() {
topPtr = nullptr;
}
It is the Stack::
that is underlined with the error "name followed by :: must be a class or namespace." If relevant, I am using VS Code.
I would just like to have a generic stack implementation, and I'm not sure why I'm getting this error? Thanks!
Upvotes: 0
Views: 116
Reputation: 217293
Syntax of out of class definition is:
template <class DataType>
Stack<DataType>::Stack() : topPtr{nullptr} {}
// ^^^^^^^^
Upvotes: 1