CS 250 Computer Programming and Problem Solving - FALL 1998 |
---|
[ Home | Syllabus | Notes | Glossary | CS250 WEB Version Home Page | Project Page | Final Study Guide]
Analysis
How about the circular problem of students contain lists of courses and courses contain lists of student?
Here are a couple of solutions and non-solutions:
class Student { Student(const Student &); // copy constructor private: SeqList<Course> Schedule; } class Course { Course(const Course &); // copy constructor private: SeqList<Student> Roster; } // copy constructors do deep copies // SeqList has a copy constructor which does deep copy
Problem: Circular construction = goes into infinite loop (check out the code)
Same as above but use a constructor which creates a "truncated copy" - that is copies everything but the List
Problem: What if something changes in original object.
class Student { Student(const Student &); // copy constructor private: SeqList<Course *> Schedule; } class Course { Course(const Course &); // copy constructor private: SeqList<Student *> Roster; } // copy constructors do deep copies // SeqList has a copy constructor which does deep copy
class Student { Student(const Student &); // copy constructor private: SeqList<VString> Schedule; } class Course { Course(const Course &); // copy constructor private: SeqList<FixedString> Roster; } // copy constructors do deep copies // SeqList has a copy constructor which does deep copy