object identity and vector erase()

This is a discussion on object identity and vector erase() within the C++ Programming forums, part of the General Programming Boards category; This might take a look of explanation, but i want to make my problem clear. I have two classes one ...

  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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21