push_back on list problem

Hi,
i have a problem with push_back:
list<Student*> students;
1
2
3
4
5
6
7
8
9
10
11
12
list<Student*> students;
void Library::addStudent(const Student& student){
	try{
		if (! find(students.front(),students.back(),student))
			throw DuplicateStudentAddind(student.getId());
		students.push_back(student); // No instance of overloaded function
		return;
	}
	catch(DuplicateStudentAddind& e){
		cout << e.what() << "(id=" <<e.getIndex() << ")" << endl;
	}
}


what is the problem ?
You have a list of pointers, but you're trying to add a student object to it.
thank you :)
another problem on almost the same function:
1
2
3
4
5
6
7
8
9
10
11
12
13
void Library::addStudent(const Student& student){
	try{
		list<Student>::iterator it;
		it = find(students.front(),students.back(),student); // cant assign to it!
                                if (it == student.back())
			throw DuplicateStudentAddind(student.getId());
		students.push_back(student);
		return;
	}
	catch(DuplicateStudentAddind& e){
		cout << e.what() << "(id=" <<e.getIndex() << ")" << endl;
	}
}
Last edited on
front() and back() return a reference to the first and last element, respectively.
However, find needs iterators, which you get with begin() and end().
can you show me the changes that i need to enteR ?
Replace front with begin and back with end.
thnx man !
Topic archived. No new replies allowed.