我应该创建一个链表(现在被要求将所有内容都放在头文件中(,我试图为节点创建一个结构,但它说它需要一个类名。我做错了什么?我对使用结构为列表创建节点有点困惑。
#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