Initialializing a std::deque
Aug 5, 2011 at 11:37pm UTC
Trying to initialize five deques from the STL library like this:
1 2 3 4
for (int i = 0; i < 5; i++)
{
deque<int > line(i);
}
Later, when I try to use the lines, (as in line(1).size()), I get an error that says 'line' was not declared in this scope.
What am I doing wrong here? Thanks.
Aug 5, 2011 at 11:56pm UTC
I am a little confused as to what you are trying to do.. initialize a deque with 5 elements? or create an array of 5 deques?
Aug 5, 2011 at 11:59pm UTC
Sorry, I'm working on a program that simulates a grocery store checkout process. I'm trying to create 5 separate std::deques that will hold the customers as they enter each of the five checkout lines.
Thanks.
Aug 6, 2011 at 12:30am UTC
You have two options,
deque<int > line[5]; // limited to default construction for each element
or
1 2 3 4 5 6 7 8
vector< deque<int > > line;
for (int i = 0; i < 5; i++)
{
line.push_back( deque<int >(i) );
}
// line[0].size(), line[1].size(), etc
Aug 6, 2011 at 2:35am UTC
Thanks. I appreciate your help.
Topic archived. No new replies allowed.