Ich bekomme den Compiler-Fehler: Fehler "Node" nennt keinen Typ. Das ist mein Kopf:Fehler nennt keinen Typ
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
template <class ItemType>
class LinkedList
{
public:
LinkedList(); // Constructor
bool isEmpty() const; // Checks if list is empty.
int getLength() const; // Returns the amount of times in the list.
bool insert(int index, const ItemType& insertItem); // Inserts an item at index.
bool remove(int index); // Removes item at index.
void clear(); // "clears" the list, but actually sets amount of items to zero.
ItemType getIndex(int index); // Returns the item at a given index.
int find(const ItemType& findItem); // Finds an item, then returns the index it was found.
void printList() const;
private:
struct Node // Struct so I can have my linked list.
{
ItemType item; // Data item.
Node* next; // Pointer to the next node.
};
int itemCount; // Current amount of items in list.
Node* headPtr; // Head/beginning of the list.
Node* getNodeAt(int position) const; // Private method to get position.
};
#include "LinkedList.cpp"
#endif // LINKEDLIST_H
Dann ist mein cav:
#include "LinkedList.h"
#include <iostream>
using namespace std;
// All the other methods, and at the very end...
template<class ItemType>
Node* LinkedList<ItemType>::getNodeAt(int position) const //Error is here.
{
Node* retPtr = headPtr;
int index = 0;
while(index != position)
{
retPtr = retPtr->next;
index++;
}
return retPtr;
}
Der Fehler ist bei der Methodensignatur in der CPP-Datei für GetNodeAt. Nach dem, was ich gelesen habe, scheinen die Fehler zu entstehen, wenn auf ein Objekt verwiesen wird, das noch nicht definiert ist, aber ich sehe nicht wirklich, wie ich diesen Fehler gemacht habe.
Danke. Ich musste nur "typename" vor dem, was Sie gerade aufgelistet haben, hinzufügen, und es funktioniert jetzt. –