簡體   English   中英

我收到未聲明的標識符錯誤,但我已包含 header 文件?

[英]I am getting an undeclared identifier error but I have included the header file?

我正在嘗試創建一個程序來幫助我更好地理解堆棧,並且在嘗試將模板實現到我的 header 文件中時遇到了這個錯誤。 這是說一堆未聲明的標識符錯誤,以及嘗試在 main.cpp 中創建新的 object 時出現意外字符。

I have already tried just making sure the header file works, so a blank main.cpp and just including the header file and it compiles like that, but when right when I try to create a new object from the header file class, I get the錯誤。 我在網上花了一些時間試圖找到類似的東西,但他們似乎都非常具體地解決了他們的問題,這對我的幫助不大。

//這是我的 header 文件的一部分:

#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();
    }
};

//這是我的main.cpp,我嘗試在其中實現header文件:

#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();
}

我希望能夠運行該程序並使用我在 class 中創建的功能,但我不斷收到未聲明的標識符錯誤。 任何幫助,將不勝感激!

改變

#include "StackAsLList.h"
#include "pch.h"

#include "pch.h"
#include "StackAsLList.h"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM