resizable arrays that contain structs

This is a discussion on resizable arrays that contain structs within the C++ Programming forums, part of the General Programming Boards category; I am working on a "game". The character is a firefighter and he starts at the bottom of a building ...

  1. #1
    Registered User help_seed's Avatar
    Join Date
    Nov 2009
    Posts
    13

    resizable arrays that contain structs

    I am working on a "game". The character is a firefighter and he starts at the bottom of a building (first node in linked list). At every level there is any number of fires. Each fire has a particular time it started at, and after a fire has burnt for too long the room is destroyed. So I made a struct that contains the time the fire started (initializedTime) and then I plan to have a resizable array for each node. So it would go firefighter comes to a level (node). There are x fires (however elements in array). He puts out the fire that's been going the longest (data inside struct). He moves to the next level (next node). Process repeats.
    My question is how can I have a resizable array of structs? Do I use the new operator or realloc? The fire may start again on a level, so new rooms catch on fire.

    Feel free to tell me that I'm going about this all the wrong way, or that I need to clarify my question.

    Thank you.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,743
    You would use a std::vector. However, the "puts out the fire that's been going the longest" suggests that a std::queue or std::priority_queue might be more appropriate.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. allocatable arrays in CLASSes and STRUCTS
    By simone.marras in forum C++ Programming
    Replies: 4
    Last Post: 03-14-2009, 10:50 AM
  2. Replies: 7
    Last Post: 06-04-2008, 10:39 PM
  3. a question on pointers, structs and arrays
    By onefootswill in forum C Programming
    Replies: 3
    Last Post: 12-06-2007, 12:27 AM
  4. arrays in structs
    By *DEAD* in forum C Programming
    Replies: 3
    Last Post: 11-25-2006, 06:35 AM
  5. malloc for structs and arrays
    By rkooij in forum C Programming
    Replies: 15
    Last Post: 05-04-2006, 07:38 AM

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