Thread: Linked List and Nodes

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    91

    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

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    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.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    183
    or u can define 'class node' at first then 'class linkedlist' .

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  2. help! Placement of nodes in a Linked List
    By lostmyshadow in forum C Programming
    Replies: 6
    Last Post: 12-17-2007, 01:21 PM
  3. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 08:55 PM
  4. Adding nodes to a linked list
    By bluescreen in forum C Programming
    Replies: 4
    Last Post: 11-09-2006, 01:59 AM
  5. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM