c++ - 错误:预期的类名(链表 C++)
问题描述
我应该创建一个链接列表(要求现在将所有内容放在头文件中)并且我正在尝试为节点创建一个结构,但它说它需要一个类名。我做错了什么?我对使用结构为列表创建节点有点困惑。
#include "LinkedListInterface.h"
#ifndef LAB03LINKEDLIST_LINKEDLIST_H
#define LAB03LINKEDLIST_LINKEDLIST_H
template <typename T>
class LinkedList: public LinkedListInterface<T>
{
public: // this is where the functions go
LinkedList();
void AddNode(T addData)
{
nodePtr n = new node;
n->next = NULL;
n->data = addData;
if (head != NULL)
{
current = head;
while (current->next != NULL)
{
current = current->next;
}
current->next = n;
}
else
{
head = n;
}
}
void DeleteNode(T delData);
void PrintList();
private:
struct node:
{
T data;
node* next;
};
typedef struct node* nodePtr;
nodePtr head;
nodePtr current;
nodePtr temp;
};
#endif //LAB03LINKEDLIST_LINKEDLIST_H
解决方案
struct node:
{
T data;
node* next;
};
应该
struct node
{
T data;
node* next;
};
:
除非您打算使用继承,否则类名后面没有- @john
推荐阅读
- prometheus - 如何将进程导出器配置为 prometheus 配置文件?
- reinforcement-learning - 使用带有目标的 DQN 时出现奇怪的结果
- javascript - 将对象数组分组并添加到复杂对象:Javascript
- angular - 等待通过 API 在构造函数中启动的数据被填充
- excel - 使用VBA识别一定范围内的第一个空列
- drawing - SwiftUI:带有内部笔划的楔形
- azure - Azure IOTEdge-网关身份验证错误
- c# - 注册 DbContext 服务
- apache - 在 .htaccess 中设置 RewriteRule 后,网站显示一个空白页面
- mysql - 为什么这个 SUM 是所有分数,而不仅仅是最好的 5 分?