the problem is I'm trying to insert to the top of the list but I keep getting an error which I'm guessing results from a destructor call to tmp. (note the passing of list as a reference variable)Code:void insertIntoList(dbase &list, char *name, int age, int number)
This is where I'm guessing the error comes up:
iterator and tmp are declared thus: dbase *iterator, *tmp;Code:if (*iterator->name > *name){
tmp = new dbase(name, age, number);
tmp->link = &list;
list = &tmp;
tmp = NULL;
}
but I'm guessing because tmp is now nullified when the destructor's called so there's nothing to destroy though it realises that the object was created earlier.
Is there a solution to my problem or should I not pass the list as a reference variable and just let the function return the object?
Thank you all for your time