"Howard" <me@here.com> wrote in message
news:zbOdnfqtlYWcc3DbnZ2dnUVZ_ruqnZ2d@comcast.com...
"Jim Langston" <tazmaster@rocketmail.com> wrote in message
news:WSlHi.85$ae3.16@newsfe02.lga...
char* fnamelink::getFirst()
{
flink* current = first;
if(current)
{
=> while(current->previous != NULL)
{
current = current->previous;
}
}
first = current;
if(first)
return first->data;
else
return NULL;
}
You are attempting to dereference a NULL pointer. Lets look at one of
your methods:
You're correct, of course, but interestingly, the location of the reported
error is in the one function which does NOT allow a NULL pointer to be
dereferenced! :-) (But once you've got undefined behavior, nothing else
can be trusted, so the location of the crash *could* be just about
anywhere.)
Yeah, the interesting this is when I compiled and tested (with a few
modifications such as changing free to delete, returning "NULL" instead of
NULL for testing, etc...) getFirst() was actually working. I think it
depends on how the class is used however, and without code showing how he
was using it, could only go on what I observed.
The intesting thing about his linked list, however, is that you can get the
first, second and last items in the list, but no other using fnamelink's
wrapper. Also, the first in the fnamelink is actually the last item in the
list, since new items are iserted before first. So to get the first item
added, he has to iterate through from the last item added XD
element (look at getNext()/getPrevious()). This means that insertions
are not necessarily made at the end either, it could be in the middle.