Me again! This time adding to the linked list

This is a discussion on Me again! This time adding to the linked list within the C++ Programming forums, part of the General Programming Boards category; Creating the function to add to the end of the list now, here's the code: Code: void CList::add(CNode *pRoot, std::string ...

  1. #1
    Let's do some coding! Welshy's Avatar
    Join Date
    Mar 2005
    Location
    Staffordshire University, UK
    Posts
    168

    Me again! This time adding to the linked list

    Creating the function to add to the end of the list now, here's the code:
    Code:
    void CList::add(CNode *pRoot, std::string input) // function to add a new node at the end
    {
    	CNode *pPointer;
    	pPointer = pRoot;
    
    	if(pPointer != 0)
    	{
    		while(pPointer->pNext != 0)
    		{
    			pPointer = pPointer->pNext;
    		}
    	}
    
    	pPointer->pNext = new CNode;
    	pPointer = pPointer->pNext;
    	pPointer->pNext = 0;
    	pPointer->name = input;
    
    }
    Now i'm pretty proud of that, as it's the best looking code i've probably ever written, lol, except that i get some weird error:

    CList.obj : error LNK2019: unresolved external symbol "public: __thiscall CNode::CNode(void)" (??0CNode@@QAE@XZ) referenced in function "public: void __thiscall CList::add(class CNode *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?add@CList@@QAEXPAVCNode@@V?$basic_string@DU?$cha r_traits@D@std@@V?$allocator@D@2@@std@@@Z)
    Debug\Linked List.exe : fatal error LNK1120: 1 unresolved externals

    It looks to me as if it should work fine, but as usual i'm completely baffled, and im asking you guys on here to help me, hehe, thanks a million

    P.S. do you need the header files code? the prototypes match so i dont see how it's anything to do with them

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,260
    hmm... could it be that you declared CNode::CNode() but never implemented it?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Let's do some coding! Welshy's Avatar
    Join Date
    Mar 2005
    Location
    Staffordshire University, UK
    Posts
    168
    yes it would, thank you very much

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  2. Problem with linked list ADT and incomplete structure
    By prawntoast in forum C Programming
    Replies: 1
    Last Post: 04-30-2005, 02:29 AM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Linked List
    By jpipitone in forum C Programming
    Replies: 4
    Last Post: 03-30-2003, 09:27 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 11:21 PM

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