#1
  1. pogremar
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2003
    Location
    At Work
    Posts
    958
    Rep Power
    13

    Question class accessor problem


    Hi,
    a couple of days ago I posted a question about the best way to dynamicaly allocated data for this program I was doing. I ended up using(and learning) linked lists. Thanks you all that helped.

    I got the program working. Hoever, in the process of optimizing it and making it object oriented I broke it.

    I have this class which holds the data:

    Code:
    class NODE
    {
    public:
    	
    	 void show();	// recursively prints data from each node. 
    	 void diskPut(FILE *); // writes data collected to disk
    	 char * getAddress();
    	 void setAddress(char *);
    	 void setNext(NODE *);
    	 NODE getNext();
    
    
    
    private:
    	char m_address[MAX_PATH];	// address of file found
    		NODE *m_next;	    // This is a pointer to "our m_next node" in our  linked list
    };
    I'm trying to use the getNext() functin to return a pointer so that I could assign it to another pointer in other to clean up things. for the sake of clarity, here's the function that I'm using:
    Code:
    void LINKED_LIST::clear()
    {
    	NODE *walker = head; // Set a "walker node" to the front of the list
    
    	while(walker != NULL)
    	{
    		NODE *temp = walker; // Create a temp node 
    
    		walker=walker->getNext(); // Move the walker to the m_next node on the list
    
    		delete temp; // Free the memory
    	}
    
    	head = tail = NULL; // Set everything to NULL
    }
    it's giving me the error that the = is not sutable to do this:
    walker = walker->getNext()
    basically I'm trying to assing walker the address of the next node. I guess the function is not returning a pointer.
    This is the definition of getNext();

    Code:
    NODE  NODE::getNext(){
    
    return this->m_next;
    }
    What's up:confused:
  2. #2
  3. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    28
    the function getNext() returns a NODE not a NODE*.

    try

    NODE* getNext();

    or dump the function and use

    walker=temp->m_next;
    Last edited by TechNoFear; July 7th, 2003 at 11:33 PM.
    The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

    Frank Zappa
  4. #3
  5. pogremar
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2003
    Location
    At Work
    Posts
    958
    Rep Power
    13
    works!
    thanks

IMN logo majestic logo threadwatch logo seochat tools logo