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
  • 30,449
  • 3
  • 47
  • 70

1 Answers1

1

Syntax of out of class definition is:

template <class DataType>
Stack<DataType>::Stack() : topPtr{nullptr} {}
//    ^^^^^^^^
Jarod42
  • 203,559
  • 14
  • 181
  • 302