-
Linked List and Nodes
linked list class
Code:
class LinkedList {
public:
LinkedList(); // constructor
~LinkedList(); //destructor
private:
Node * headPtr; //wont let me do this why ???
};
node class
Code:
class Node {
public:
Node();
~Node(); //destructor
Node* nextPtr;
int item;
};
im trying to make a linked list. not sure if this is the correct way.
basically i have a headPtr that points to the head of hte list. But i cant seem to define it in LInkedlist.h.
I want to define it there because all the funcitons in LinkedList.cpp need to modify/read the items in the linked list..
not too sure how to do this.. if anyone could help thanks heaps :D
-
Your LinkedList class needs to know what a Node is. Use a #include to include Node.H (or whatever you are calling it) in LinkedList.H and it should work.
-
or u can define 'class node' at first then 'class linkedlist' .