#### Archived

This topic is now archived and is closed to further replies.

# STL - list<queue<int> >

This topic is 6194 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Well for the timeline in my game i need a list of queues of a selfwriten class. To make the example less complex i use a list of queues of ints:
  #pragma warning(disable:4786) #include #include #include using namespace std ; int main() { list > my_timeline: } 
Well my question is how do i use this thing? Lets say i want: to put the numbers 2,3,5 in the first knot of the list an empty que in the second list knot. What must i write? Please help. Edited by - Jonus on August 2, 2001 1:39:04 PM

##### Share on other sites
Well, it gets a little messy, honestly. Since your list is holding a complicated object (as opposed to a simple type), you''ll need to put instances of that type in the list.

For example:

  queue temp; // when we first create this, it''s empty...// ...so we can create the first "knot"temp.push_back(2);temp.push_back(3);temp.push_back(5);// put it in the listmy_timeline.push_back(temp);// now want an empty list for the next "knot" (we always have to clear it, of course, unless we want 2, 3, and 5 hanging around)temp.clear();// put it in the listmy_timeline.push_back(temp);

Now, if you want to modify queues already in the list, you''ll have to use an iterator to obtain a pointer to the particular queue you''ll want, then operate on it through that pointer.

##### Share on other sites
Thank you merlin9x9. That was exactly the information i needed (create temp instance and use it to create the knots).

I know how to use the containers, but i haven''t used a concainer for a container yet. Again thx.

##### Share on other sites
Your realization that there needs to be a space between the last two greater-than signs makes you better than I...it took me a long time to figure out that omitting the space made the compiler think I had a right-shift in there.

##### Share on other sites
You can use three >>> and it compiles and runs correctly
Don''t ask me, I don''t know why .

##### Share on other sites
I also believe you can use the [] operator to access the elements like in a 2d array. I''m not sure if you need ()''s but I use them just in case.

example:
(my_timeline[1])[2]
This line would access the first element in the list(the first queue) and the 2nd element in the queue (some number)

Later,
Eck

##### Share on other sites
Sadly, list has no operator[]. This is because list is almost always implemented as a linked list—if not, it behaves like one. As such, how would you get an index value for nodes that are potentially scattered all over the place? There are ways, of course, but most of them essentially offset the advantages of using something like list rather than vector in the first place.

Since I''m talking about vector now, maybe you can use vector instead so you can use indexing rather than messy iterators. If there''s some way you can know ahead of time how many items you''re going to store, use vector''s reserve function (passing it the number of items you''re going to add) to make it allocate the space ahead of time so it won''t reallocate for each addition. And once you''ve done that, the benefit is that all kinds of access are cheap; in contrast, list is slow for all but linear access.

##### Share on other sites
I am trying to rebuild the Active Time System of Final Fantasy Tactics.

FFT is not based on which Faction is at turn but which Character
is at turn. Every Character has its own Speed Attribute (e.g. Thief has speed 6, a heavy Knight 4).

Its easy to determine which character is at turn (not really), but when you try to predict, which will be the next twenty Chars at turn, it gets really complicated (plus there are spells which take influence on the flow of time).

IMHO this Problem can only be solved with a list of queues of player_on_map. (:

Cool beans.

1. 1
Rutin
25
2. 2
3. 3
4. 4
JoeJ
17
5. 5

• 14
• 11
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
631756
• Total Posts
3002109
×