List as a Class attribute.

Hi! First of all, please excuse my english level, it's not my native language.

Now, I'm creating a class and I have an attribute that has to be a list. My class is "Student", and the attribute that I want to be a List type is actually a class named "Regular_Subjects", so I did it like this:

(The following code its Student.h file)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  #ifndef Student_H
  #define Student_H

  #include <list>

  class Student
  {

  protected:
	string NumMatricula;
	string RutAlumno;
        string NomAlumno;
        string AnoIngreso;
        list<Regular_Subjects> Subjects;


Please ignore all of the string attributes. As I said, I have a "Regular_Subjects" class that has its own information and I need that every Student has a list of Subjects with all that information.
Is it right to declare it like that?
And if so, where should I use this lines?

list<Regular_Subjects>::iterator P;
P = Subject.begin();

I've found several examples using and explaining Lists in main function, but I don't know if I can do the same in a class.

For the record, I instance the constructor, getters and setters on a Student.cc file.

I hope I explained myself clear, I've been looking for a solution or and explanation but I can't find it and it's an assignment :(
By the time the complier reaches line 14 of your header file it would need to have seen class Regular-Subjects, either as a declaration, defintion or at the very least, forward declaration. So the minimum requirement should be:
1
2
3
4
5
6
7
8
9
10

class Regular_Subjects;
class Student
{
	protected:
		...
		list<Regular_Subjects> Subjects;
	public:
		list<Regular_Subjects> getSubjects() const {return Subjects;}
}

And if so, where should I use this lines?
You can use them wherever you want but rememeber to scope the iterator properly and use getters:
1
2
list<Regular_Subjects>::iterator P;
P = Student::getSubjects.begin(); 

Topic archived. No new replies allowed.