Thread: Quick question on vectors

  1. #1
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879

    Quick question on vectors

    Hey, just wondering:

    Code:
    std::vector<Stuff> stuffs;
    for(int i = 0; i < 5; ++i)
    {
         stuffs.push_back(Stuff());
    }
    //more stuff goes here
    OK, so now we've got a vector of Stuff's called stuffs, and it is holding 5 Stuff's. Do I have to manually remove each Stuff from the vector before the program ends, or is that built into its destructor or something?...

    Code:
    while(stuffs.size() > 0)          //Is this
    {                                 //part
         stuffs.erase(&stuffs[0]);    //necessary
    }                                 //here?
    Last edited by Hunter2; 07-24-2002 at 03:41 PM.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  2. #2
    Registered User
    Join Date
    Jul 2002
    Posts
    66
    Off the top of my head, unless the items in the vector are dynamically allocated then you shouldn't have to worry about it.

  3. #3
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Does "dynamically allocated" mean something like "created using the new keyword"?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  4. #4
    Unregistered
    Guest
    built in destructor will handle getting rid of the memory for you, just like built in methods allow you to add new memory without your calling the new operator directly.

  5. #5
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Ok, thanks!


    _______________
    P.S.

    If my computer begins mysteriously crashing and the program doesn't work, I know who to blame
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. quick question (adding characters)
    By Cactus in forum C Programming
    Replies: 2
    Last Post: 09-24-2005, 03:54 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM