使用模板进行堆栈实现; "name followed by :: must be a class or namespace"
Using a template for a stack implementation; "name followed by :: must be a class or namespace"
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
};
到目前为止stack.cpp:
#include "stack.h"
//using namespace std;
template <class DataType>
Stack::Stack() {
topPtr = nullptr;
}
Stack::
的下划线中有错误"name后跟::must be a class or namespace"。如果相关,我使用的是VS Code。
我只想有一个通用的堆栈实现,但我不确定为什么会出现这个错误?谢谢
类外定义的语法为:
template <class DataType>
Stack<DataType>::Stack() : topPtr{nullptr} {}
// ^^^^^^^^
相关文章:
- 使用模板进行堆栈实现; "name followed by :: must be a class or namespace"
- 尝试链接我的着色器时,我收到错误代码"error c5145 must write to gl_position"
- 为什么static_assert错误:即使我传递常量"expression must have a constant value"?
- 错误:"Left of getValue must have class/struct/union"
- C++/SDL "initial value of reference to a non-const must be an lvalue"
- 将 std::thread by 值推送到列表中
- MATLAB to C++: csvread() not supported by MATLAB Coder
- C++复制函数重载导致"must be a nonstatic member function"错误
- C++ 错误:"array must be initialized with a brace-enclosed initializer"
- Makefile by ocaml 和 cpp 扩展名
- "expression must be a modifiable lvalue"是什么意思?
- unordered_set .find 方法无法编译的 C++ "expression must have class type"错误
- C++ OpenCV Randu 函数抛出'Integer division by zero'
- 当两个成员位于同一类中时出错"a nonstatic member reference must be relative to a specific object"
- 从函数 BY VALUE 返回数组,返回结构时会发生什么?
- 编译为 cuda 内核调用提供了"expression must have integral or unscoped enum type"
- 如何在不受其他文件影响的情况下"by itself" Visual Studio 项目中运行C++文件?
- 调用 list.size() 方法给出错误"expression must have class type"
- "[ptr, ptr+len) must be a valid range"是什么意思?
- MacPorts:"Error: clang-4.0 has been replaced by clang-8.0; please install that instead",但我已经安装了clang