Click to See Complete Forum and Search --> : Linking Errors


GraemeW
April 17th, 2003, 05:00 AM
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::DisplayFleet()' referenced from C:\....MAIN.OBJ


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

PaulWendt
April 17th, 2003, 06:18 AM
What the error means is that list::DisplayFleet() has no compiled
code for it. What is the declaration of list::DisplayFleet()? 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:

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

GraemeW
April 17th, 2003, 07:07 AM
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'

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.

PaulWendt
April 17th, 2003, 07:31 AM
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

GraemeW
April 17th, 2003, 10:26 AM
class list
{
public:
void ToFirst( void ); // Move to first node

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,

PaulWendt
April 17th, 2003, 11:52 AM
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