Thread: object identity and vector erase()

  1. #1
    Kyle
    Join Date
    Jan 2005
    Posts
    5

    object identity and vector erase()

    This might take a look of explanation, but i want to make my problem clear. I have two classes one called Student and the othe Course, each one points to each other and preserves object identity. the Student class has a vector of Course* (course pointers) and Course has a dynmaic array of Student pointers. I need to write a function called

    Code:
    void drop_course(Course* c) //Student function that takes a course                                                                //pointer
    This function must use iterators to remove the Course form the student and also the Course must then remove the student.

    Also i need to write a function in my driver that will drop all the courses the student is in.

    Again i must use iterators

    Does any one have any advice im fairly new to the concept of object identity and the use of iterators.
    Thanks alot!

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Check out std::find().
    Alternatively iterate the vector manually with an iterator (std::vector<Course*>::iterator).
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed