Thread: Linked Lists error: m_deck undeclared identifier

  1. #16
    Registered User
    Join Date
    Nov 2007
    Posts
    56
    Oh.
    I've been staring at this for so long I've stopped recognizing error messages. I initialized cvalue to 0.
    I'm sure I'll be back on in a few minutes.

  2. #17
    Registered User
    Join Date
    Nov 2007
    Posts
    56
    I have a new unhandled exception, and I think it's coming from my insert function which is defined as follows:
    Code:
    void CDeck::insert(int index, s_card c)
    {
    	if(empty()||index==1)
    	{
    		insertAtHead(c);
    	}
    	else
    	{
    		cardNodeptr cur = head;
    		cardNodeptr prev = NULL;
    
    		for(int x=1; x<=index; x++)
    		{
    			prev = cur;
    			cur = cur->next;
    		}
    		cardNodeptr newPtr = cur;
    		newPtr->item = c;
    	}
    }
    
    void CDeck::insertAtHead(s_card c)
    {
    	cardNodeptr cur = new cardNode;
    	cur->next = head;
    	cur->item = c;
    	head = cur;
    }
    It might be helpful to know how I typedef my pointers:

    Code:
    struct s_card
    {
    	int value;
    	char suit;
    };
    
    struct cardNode
    {
    	s_card item;
    	cardNode *next;
    };
    
    typedef cardNode * cardNodeptr;
    And I did define cardNode *head as a private data member.
    Last edited by marQade; 05-16-2008 at 01:47 PM. Reason: See when I learn this, I'll never forget how LL's work.

  3. #18
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Where is the guarantee that this loop won't attempt to go beyond the end of the list?
    Code:
    		cardNodeptr cur = head;
    		cardNodeptr prev = NULL;
    
    		for(int x=1; x<=index; x++)
    		{
    			prev = cur;
    			cur = cur->next;
    		}
    What is the purpose of this function? Does it insert new nodes or does it modify the contents of existing nodes? I think you should pick one of those, do that well, and perhaps rename the function to reflect what it does if you decide it shouldn't actually insert nodes.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM