removing objects from std::vector

This is a discussion on removing objects from std::vector within the C++ Programming forums, part of the General Programming Boards category; Hi, i have encountered a problem, i would like to remove element i from my list, which is of type ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    11

    Question removing objects from std::vector

    Hi,
    i have encountered a problem, i would like to remove element i from my list, which is of type vector.

    I have the following code, within the declaration of my list (vector):

    //create an array that holds one element, this is on the next line assigned to the element which i want to delete:
    MyObject** o = new MyObject* [1];

    //this should point to the object that i want to delete:
    *o=getMyObject(i);

    //this should remove it (but it gives me a run-time memory error)
    list.erase(o);


    any suggestions?

    thanks,
    xagiber
    I use BorlandBuilder 5

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    The erase() STL function deletes the element that an iterator points to. The remove() STL function deletes the equivalent element. Consider remove().

    Kuphryn

  3. #3
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Is remove standard? It isn't in the dinkum library.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 60
    Last Post: 12-20-2005, 10:36 PM
  2. Question about cout an stack object?
    By joenching in forum C++ Programming
    Replies: 8
    Last Post: 05-08-2005, 10:10 PM
  3. chain of objects within pop framework help needed
    By Davey in forum C++ Programming
    Replies: 0
    Last Post: 04-15-2004, 10:01 AM
  4. Replies: 4
    Last Post: 10-16-2003, 11:26 AM
  5. array of objects?
    By *~*~*~* in forum C++ Programming
    Replies: 4
    Last Post: 05-31-2003, 05:57 PM

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