View Single Post
Old Sep 5th, 2006, 2:39 AM   #2
Cache
Hobbyist
 
Join Date: Sep 2005
Posts: 261
Rep Power: 4 Cache is on a distinguished road
'current' is always dereferenced in 'list::showlist' even if it's invalid (currentSize == 0). You might want something along the lines of:

void list::showlist()
{
    if (currentSize)
    {
        cout<<"\n\n********************************************************"<<endl;
        cout<<"size:\t"<<currentSize<<"\n"<<endl;
        cout<<"current val:\t"<<current->nodeData<<"\n"<<endl;
        cout<<"current->next:\t"<<current->next<<"\n"<<endl;

        int i = 1;
        for(node * temp = head; temp != 0; temp = temp->next)
        {
            //display that info
            cout<<"element "<<i<<"\t"<<temp->nodeData<<endl;
            i++;            
        }
        cout<<"\n\n********************************************************@"<<endl;
    }
    else
    {
        // Don't dereference invalid pointers.
    }
}
There may be other things wrong too, that just stands out. Aslo:
template<typename Ty>
void function(const Ty& val)
{
}

// ...
struct test {};
test tester;
function(tester);
Cache is offline   Reply With Quote