I'm new at C++... I'm making some classes - one for Student and one for Courses. There is an "list" inside of Courses that adds Student Objects.
I am able to add a student:
void Course::addStudent(Student student)
{
classList.push_back(student);
}
But when I go to delete a Student, I'm not able to remove it. I'm getting a long error about Student not be derived and something about the operator==(const allocator).
void Course::dropStudent(Student student)
{
classList.remove(student);
}
Any suggestions? Thanks!!
I was referring to this website for how to add/remove elements: http://www.cplusplus.com/reference/list/list/remove/
Student Code:
class Student {
std::string name;
int id;
public:
void setValues(std::string, int);
std::string getName();
};
void Student::setValues(std::string n, int i)
{
name = n;
id = i;
};
std::string Student::getName()
{
return name;
}
Full Course code:
class Course
{
std::string title;
std::list<Student> classList; //This is a List that students can be added to.
std::list<Student>::iterator it;
public:
void setValues(std::string);
void addStudent(Student student);
void dropStudent(Student student);
void printRoster();
};
void Course::setValues(std::string t)
{
title = t;
};
void Course::addStudent(Student student)
{
classList.push_back(student);
}
void Course::dropStudent(Student student)
{
classList.remove(student);
}
void Course::printRoster()
{
for (it=roster.begin(); it!=roster.end(); ++it)
{
std::cout << (*it).getName() << " ";
}
}
Studentconsists of. IfclassListis astd::list, thenremove()requires thatStudentrequires an equality operator (operator ==)