new linked list error - undeclared identifier
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: new linked list error - undeclared identifier

  1. #1
    Join Date
    May 2013
    Posts
    11

    new linked list error - undeclared identifier

    I dynamically allocate a new list in the recMergeSort function which should run a constructor but when it get to the functions that use it, I get error C2065: 'otherHead' : undeclared identifier. I have tried setting it to NULL and it didn't work. I even copied the default constructor to a set function and I still get the errors.

    Code:
    template<class Type>
    void unorderedLinkedList<Type>::recMergeSort(nodeType<Type>* &head)
    {	
    	
    	otherHead = new nodeType<Type>;
    
    	if (head !=NULL)
    		if (head->link != NULL)    
    		{
    			divideList(head, otherHead);
    			recMergeSort(head);
    			recMergeSort(otherHead);
    			head = mergeList(head, otherHead);
    		}
    }
    I'm beginning to wonder if I'm sending the correct data type. Here is the heading of the functions that I'm using from the book. Any suggestions?

    Code:
    void unorderedLinkedList<Type>::divideList(nodeType<Type>* first1,
    	nodeType<Type>* first2)

  2. #2
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,453

    Re: new linked list error - undeclared identifier

    Where is otherHead defined and of what type?
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  3. #3
    Join Date
    Apr 1999
    Posts
    27,430

    Re: new linked list error - undeclared identifier

    Quote Originally Posted by luvCats View Post
    I dynamically allocate a new list in the recMergeSort function which should run a constructor but when it get to the functions that use it, I get error C2065: 'otherHead' : undeclared identifier.
    Why would this be strange? I don't see where you declared "otherHead" ,so why is it surprising that the compiler doesn't see it?

    Regards,

    Paul McKenzie

  4. #4
    Join Date
    May 2013
    Posts
    11

    Re: new linked list error - undeclared identifier

    I thought I had declared it. I also tried this code.

    Code:
    nodeType<Type> *otherHead;
    and I still get the same error.

  5. #5
    Join Date
    Apr 1999
    Posts
    27,430

    Re: new linked list error - undeclared identifier

    Quote Originally Posted by luvCats View Post
    I thought I had declared it. I also tried this code.

    Code:
    nodeType<Type> *otherHead;
    and I still get the same error.
    The problem with how your posting code is the "I thought". We can't look into your computer, or look inside of your thoughts.

    When you get a compiler error, you should post the real code you're compiling as one unit, not pieces of code here and there. That declaration could be anywhere as far as we're concerned. Compiling is an exact science -- fuzzy examples with missing or disjoint pieces of code doesn't cut it.

    Please post the complete, but smallest example that duplicates the compiler error. "Complete" meaning we don't have to add, remove, or improvise what you post just to get the compiler to give us the same error. By doing this, you may come across the reason why the error occurred.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; May 30th, 2013 at 09:09 PM.

  6. #6
    Join Date
    Apr 1999
    Posts
    27,430

    Re: new linked list error - undeclared identifier

    Quote Originally Posted by luvCats View Post
    I dynamically allocate a new list in the recMergeSort function which should run a constructor but when it get to the functions that use it, I get error C2065: 'otherHead' : undeclared identifier. I have tried setting it to NULL and it didn't work.
    Another misconception -- you don't fix compiler errors by assigning values to the missing identifier.

    You fix an undeclared identifier by moving the identifier into the scope of where it is used.

    Regards,

    Paul McKenzie

  7. #7
    Join Date
    May 2013
    Posts
    11

    Re: new linked list error - undeclared identifier

    Nevermind. I think the issue is with Visual Studio. It has been giving me weird errors for these past two days whenever I make a new file. Sometimes I get the COFF error. The old programs seem to work fine.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center