I have to make a list using OOP in c++. It is supposed to have functions add, append, display, find, clear and delete.
I have succeeded with all functions except delete. The error is
for prev->getnext()* : "Lvalue required as left operand of assignment"
The classes:
class student
{
private:
string name;
string faculty;
student *next;
public:
student()
{
next = NULL;
}
student(string n, string f)
{
next = NULL;
name = n;
faculty = f;
}
void setname(string n)
{
name = n;
}
void setfac(string f)
{
faculty = f;
}
void setnext(student* stn)
{
next = stn;
}
student*getnext()
{
return next;
}
string getname()
{
return name;
}
string getfac()
{
return faculty;
}
};
class studentlist
{
student *head;
public:
studentlist()
{
head = NULL;
}
void addstudent(string n, string f)
{
student *newstud = new student;
newstud->setname(n);
newstud->setfac(f);
newstud->setnext(head);
head = newstud;
}
void del(string n, string f);
student* gethead()
{
return head;
}
};
and here is the function
void studentlist::del(string n, string f)
{
student *current;
student *aft;
student *prev;
current = head;
while((current != NULL) && (current->getname() == n and current->getfac() == f))
{
prev = current;
current = current->getnext();
if(current = NULL)
return;
if(current->getname() == n and current->getfac() == f)
{
prev = current;
prev->getnext() = current->getnext(); >here is the problem
delete current;
}
I don't understand how prev
does not have any value.