using g++ compiler and keep getting compile error:
linkedlist::processinputs(int, linkedlist)/var/tmp/ccd3DhwG.o
ld:fatal:Symbol referencing errors. No output written
collect2: ld returned 1 exit status
here is the code:
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include "linkedlist.h"
linkedlist::linkedlist(char *s) // class constructor
{
strcpy(classname,s);
}
int processinputs(int in, linkedlist lst) // processinputs selects function for user
{
switch (in)
{
case 1:
lst.addElement();
break;
case 2:
lst.deleteElement();
break;
case 3:
lst.queryElement();
break;
default:
return -1;
}
return 0;
}
void linkedlist::addElement() // fills new student structure and adds to list
{
int resp;
student head, *last;
student *stuptr;
head.next=NULL;
head.prev=NULL;
last=&head;
stuptr=new student;
cout<<" Enter name: ";
cin>>stuptr->name;
cout<<" Enter ID#: ";
cin>>stuptr->id;
cout<<" Enter the Major (1:Compsci 2:MIS 3:Elect 4:other): ";
cin>>resp;
switch (resp)
{
case 1:
stuptr->major=comp_sci;
break;
case 2:
stuptr->major=MIS;
break;
case 3:
stuptr->major=Elect;
break;
case 4:
stuptr->major=Others;
break;
}
if( firstelement == NULL)
{
firstelement=stuptr;
lastelement=stuptr;
stuptr->next=NULL;
stuptr->prev=NULL;
}
else
{
lastelement->next=stuptr;
stuptr->prev=lastelement;
stuptr->next=NULL;
lastelement=stuptr;
}
}
void linkedlist::queryElement() //searches list for element ID
{
int theid;
cout<<" Enter ID to check: ";
cin>>theid;
currentelement=firstelement;
do
{
if(currentelement->id == theid)
{
cout<<" Student found ";
cout<<currentelement->name;
}
}
while(currentelement != NULL);
}
void linkedlist::deleteElement() // deletes element from list
{
if(currentelement->prev==NULL)
{
firstelement=firstelement->next;
}
else
{
currentelement->prev->next=currentelement->next;
}
if(currentelement->next==NULL)
{
lastelement=lastelement->prev;
}
else
{
currentelement->next->prev=currentelement->prev;
}
delete currentelement;
}
void linkedlist::manipulate(linkedlist list) // manipulate called by manip_courses.cpp.
// menu for user to select a function
// linkedlist calls processinputs.
{
int input, retval;
while(1)
{
system("clear");
if(retval==-1)
{
cout<<"Input last entered was invalid"<<endl;
}
cout<<" WELCOME TO THE LINKED LIST PROGRAM"<<endl<<endl;
cout<<" Enter 1 to create a student record"<<endl;
cout<<" Enter 2 to delete a student record"<<endl;
cout<<" Enter 3 to query the records"<<endl;
cout<<" Enter 4 to quit"<<endl;
cout<<": ";
cin>>input;
if ( input==4 )
{
system("clear");
break;
}
retval=processinputs(input,list);
}
}
linkedlist::~linkedlist() // class destructor
{
if (firstelement==NULL||lastelement==NULL)
{
return; // list is empty there is nothing to delete.
}
else
{
while(1)
{
if (lastelement->prev==NULL)
{
delete lastelement;
break;
}
lastelement=lastelement->prev;
delete lastelement->next;
}
}
thanks for your help.