CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Linking Errors

  1. #1
    Join Date
    Apr 2003
    Posts
    64

    Linking Errors

    Hi All,

    Im using Borland C++ Builder 6, I have been writting a small program which utilizes linked lists to store information.

    I need to print information for each node then move to the next node and print that information etc. I set a up a while loop which tests that it isn't the end of the list, if not it prints the info for the current node and moves to the next.

    Until I added this last piece of code the program was working fine but now I get a:

    [Linker Error] Unresolved external 'list:isplayFleet()' referenced from C:\....MAIN.OBJ
    Code:
            ToFirst(); // Move to first node in list
            while ( !AtLast() )
            {
                    RetrieveInfo(); // Display info for current node
                    AdvanceNext(); // Advance to next node in list
            }
    The error must be in this piece of code, this code exists within the the cpp file of the class list. Basically I don't know how to call functions within functions of a class. (hope you understand what I mean).

    In my main file I would do it like:

    list.DisplayFleet(), but say when I move to this operation within my class and then want to call other operations on the same object, how would I do that? Obviously I can't type list.RetrieveInfo() because the operation won't know what "list" is.

    Any help greatly appreciated
    Last edited by GraemeW; April 17th, 2003 at 06:52 AM.

  2. #2
    Join Date
    May 2000
    Location
    Phoenix, AZ [USA]
    Posts
    1,347
    What the error means is that list:isplayFleet() has no compiled
    code for it. What is the declaration of list:isplayFleet()? Where
    do you have the definition? What is list? Is it a template class
    or just a plain-old class? As a style point, a linked list shouldn't
    have a function called "DisplayFleet"; what's a "fleet"? A linked
    list shouldn't worry about what it's holding; look at std::list's
    documentation if you don't believe me.

    Your code snippet is a little confusing. When you put void ToFirst(),
    that function is NOT called. What you're doing is declaring the
    function ... not calling it. If you're not trying to call it, why are you
    putting that stuff in a while loop? I can only imagine that you're
    trying to call these functions but have the syntax wrong. If you
    are only trying to call the functions, here's what it'd look like:
    Code:
           ToFirst(); // Move to first node in list
            while ( !AtLast() )
            {
                    RetrieveInfo(); // Display info for current node
                    AdvanceNext(); // Advance to next node in list
            }
    Of course, this assumes that all of these functions are valid.

    --Paul

  3. #3
    Join Date
    Apr 2003
    Posts
    64
    Hi Paul,

    Sorry I should have removed the "void's", what happened was a bunch of errors were generated, so i tried putting void infront and they dissapeared. Unfortunatly I forgot to remove them before posting here.

    I understand exactly what you mean about a list not worrying about what its holding and have removed any reference to such.

    Ill give you an update of where the program stands atm.

    The linker error has gone and now im left with:

    [C++ Error] list.cpp(145): E2268 Call to undefined function 'ToFirst'
    Code:
    void Display( void )               // Display list details
    {
            ToFirst(); // Move to first node in list
            while ( !AtLast() )
            {
                    RetrieveInfo(); // Display info for current node
                    AdvanceNext(); // Advance to next node in list
            }
    }
    Can someone tell me how to call an operation on an object, when you are already within an operation of the same object?

    Thanks for your help Paul.

  4. #4
    Join Date
    May 2000
    Location
    Phoenix, AZ [USA]
    Posts
    1,347
    If ToFirst() is actually a member function of your class, then you're
    fine. What I was insinuating in my last post [but never explicitly
    stated] we probably need a little more code to help you. Your
    error message seems to indicate that ToFirst() isn't a valid
    member function. Why don't you post your class declaration?

    --Paul

  5. #5
    Join Date
    Apr 2003
    Posts
    64
    Code:
    class list
    {
    public:
            void ToFirst( void );                    // Move to first node
    Code:
    void list::ToFirst( void )              // Move to first node
    {
            cur = head; // Sets the current node pointer to the head of the list (start)
            prev = NULL; // Since the current node is now the first, there can't be a previous node
    }
    Thanks Paul,

  6. #6
    Join Date
    May 2000
    Location
    Phoenix, AZ [USA]
    Posts
    1,347
    Well, the only thing I can really think of is that you're entering
    a naming clash with std::list. std::list should reside in the std
    namespace, but perhaps it does not for your compiler. Try
    renaming list to List and see if that helps....

    The code itself looks syntactically correct to me.

    --Paul

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured