我应该创建一个链接列表(要求现在将所有内容都放在头文件中),并且尝试为节点创建一个结构,但是它说它需要一个类名。我做错什么了?我对使用结构为列表创建节点感到困惑。
#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
关于c++ - 错误:预期的类名(链接列表C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62790608/