Reputation: 1113
I have a class Course with information about a course in the university (like when in starts, how long it is, which day of the week, etc). Now I have to do a class Semester with an undefined length of courses :
class Semester {
public :
void addCourse(Course c);
private :
Course* courses;
}
So I'd like to know how can I do the addCourse function so that I can add infinite number of courses (class Course) to my class Semester ?
Upvotes: 1
Views: 65
Reputation: 42939
Take a look at the code below:
class Semester {
public :
void addCourse(Course *c) { courses.push_back(c); }
private :
std::vector<Course*> courses;
};
Upvotes: 1