stl containers remove, clear

This is a discussion on stl containers remove, clear within the C++ Programming forums, part of the General Programming Boards category; When you remove an object from an stl container. Is the destructor for the object called? Do you need to ...

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    450

    stl containers remove, clear

    When you remove an object from an stl container. Is the destructor for the object called?
    Do you need to keep a refrence to the object and call the destructor explicitly.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >When you remove an object from an stl container. Is the destructor for the object called?
    It would be terribly inconvenient if it weren't, don't you think?

    >Do you need to keep a refrence to the object and call the destructor explicitly.
    You rarely need to call a destructor explicitly. Unless you're sure, assume that the standard library will "do the right thing".
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Jul 2003
    Posts
    450
    Thnks Prelude was just a little worried and unsure.

  4. #4
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    If your unsure, write a small test program. (eg One where the destructor just prints something and see if it is called when you remove the object.)

    Cheers
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Objects or pointers in STL containers?
    By zacs7 in forum C++ Programming
    Replies: 7
    Last Post: 06-23-2009, 10:25 AM
  2. Using delete to clear a STL vector
    By starkhorn in forum C++ Programming
    Replies: 2
    Last Post: 05-19-2005, 02:59 AM
  3. How to Clear in Visual C++
    By MyDestiny in forum Windows Programming
    Replies: 4
    Last Post: 03-16-2005, 09:40 PM
  4. Yet another clear screen thread :D
    By kermit in forum Linux Programming
    Replies: 2
    Last Post: 11-20-2003, 04:14 AM
  5. Using a button to clear a list box!
    By Unregistered in forum C++ Programming
    Replies: 13
    Last Post: 08-23-2002, 07:44 PM

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