Linked List and Nodes

This is a discussion on Linked List and Nodes within the C++ Programming forums, part of the General Programming Boards category; linked list class Code: class LinkedList { public: LinkedList(); // constructor ~LinkedList(); //destructor private: Node * headPtr; //wont let me ...

  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,674
    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.
    I used to be an adventurer like you... then I took an arrow to the knee.

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    164
    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, 12: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, 12:59 AM
  5. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 09:33 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21