Reputation: 11
I'm supposed to create a linked list (asked to put everything for now in header file) and I am trying to create a struct for nodes but it says it needs a class name. What did I do wrong? I am a bit confused on using a struct to create nodes for the list.
#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
Upvotes: 1
Views: 85
Reputation: 3197
struct node:
{
T data;
node* next;
};
Should be
struct node
{
T data;
node* next;
};
There is no :
after a class name unless you intend to use inheritance - @john
Upvotes: 1