Initialializing a std::deque

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.
closed account (DSLq5Di1)
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?
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.
closed account (DSLq5Di1)
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 
Thanks. I appreciate your help.
Topic archived. No new replies allowed.