我收到未声明的标识符错误,但我已包含头文件?
I am getting an undeclared identifier error but I have included the header file?
我正在尝试创建一个程序来帮助我更好地理解堆栈,但在尝试将模板实现到我的头文件中时遇到了此错误。它说的是一堆未声明的标识符错误,以及尝试在 main.cpp 中创建新对象时意外的字符。
我已经尝试过确保头文件正常工作,所以一个空白的主文件.cpp并且只包含头文件,它像那样编译,但是当我尝试从头文件类创建新对象时,我得到错误。我花了一些时间在网上试图找到类似的东西,但他们似乎都非常明确地解决了他们的问题,这对我并没有太大帮助。
这是我头文件的一部分:
#ifndef STACKASLLIST_H
#define STACKASLLIST_H
using namespace std;
template<typename T> class StackAsLList
{
private:
struct StackNode
{
T ch;
StackNode<T> *next;
};
StackNode<T> *top;
public:
StackAsLList();
void ClearStack(); /// Remove all items from the stack
void Push(T ch); /// Push an item onto the stack
T Pop(); /// Pop an item from the stack
bool isEmpty(); /// Return true if stack is empty
bool isFull(); /// Return true if stack is full
~StackAsLList() /// Class destructor
{
ClearStack();
}
};
这是我的主要.cpp我尝试实现头文件的地方:
#include "StackAsLList.h"
#include "pch.h"
#include <iostream>
using namespace std;
int main()
{
//this is the line where I start getting errors
StackAsLList<char>*theStack = new <char>StackAsLList();
}
我希望能够运行该程序并使用我在类中创建的函数,但我不断收到未声明的标识符错误。任何帮助将不胜感激!
更改
#include "StackAsLList.h"
#include "pch.h"
自
#include "pch.h"
#include "StackAsLList.h"
相关文章:
- 使用mongocxx驱动程序时包含头文件问题
- 如何为包含头文件的目标编写生成文件?
- 如何在 CMakeLists.txt Qt Creator 中包含头文件?
- 当包含头文件的文件不在根项目文件夹中时,如何包含它
- 在生成文件先决条件中包含头文件的原因
- My Project的属性配置正确,但Visual Studio仍然无法打开包含头文件
- 在 PostgreSQL C 扩展中包含头文件
- 是否可以在C++中以间接方式包含头文件
- 是否需要包含头文件?
- 我收到未声明的标识符错误,但我已包含头文件?
- 为什么我们需要构建一个提升库,仅仅包含头文件还不够吗,因为提升是模板
- C++:当顺序真正重要时,如何保证在项目中包含头文件的顺序
- 如何在C++中包含头文件时错误地重载
- 我在C++中无效使用不完整的类型类错误,如何正确包含头文件?
- 虚幻引擎4.16,C++包含头文件
- C++多次包含头文件
- 令牌之前的预期类名 '{' - 包含头文件和 CPP 文件
- 在.cpp中包含头文件会导致令人讨厌的错误
- 如何列出用于在Qt项目中包含头文件的所有路径
- 尽管包含头文件,但仍找不到嵌套命名空间