【发布时间】:2026-02-18 14:25:03
【问题描述】:
我有我的类 Queue(在 Queue.h 中声明并在 Queue.cpp 中实现)和 Queue.h 文件中定义的“节点”结构,如下所示:
Queue.h
//...
typedef int TElem;
struct Node{
TElem data;
Node *next;
};
class Queue
{
private:
Node *head;
Node *tail;
public:
// ... some other methods
}
然后,在 Queue.cpp
//...
Queue::Queue()
{
head = nullptr;
tail = nullptr;
}
我的构造函数中的最后 2 行代码产生 4 个错误,每行两个: '标识符“head”未定义'/'标识符“tail”未定义'和“'head':未声明的标识符”/“'tail':未声明的标识符”。为什么会这样,我该如何解决?我已经阅读了类似问题的答案,但没有人回答我的问题。
【问题讨论】:
标签: class pointers struct header identifier