0

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!

Jesper Juhl
  • 28,933
  • 3
  • 44
  • 66

1 Answers1

1

Syntax of out of class definition is:

template <class DataType>
Stack<DataType>::Stack() : topPtr{nullptr} {}
//    ^^^^^^^^
Jarod42
  • 190,553
  • 13
  • 166
  • 271