-
November 21st, 2003, 09:26 AM
#1
STL deque problem
Hi,
I'm novice in STL C++ librari, so my question will be very easy.
I have a structure, for example:
typedef struct _mystruct
{
char name[256];
bool sex;
int age;
} mystruct, *pmystruct;
I can define a class based on queue STL template:
typedef queue<mystruct, list<mystruct> > MEMBERS_QUEUE; // This works perfectly
But I want also define a class based on deque:
typedef deque<mystruct, list<mystruct> > MEMBERS_DEQUE; // This doesn't work.
I suspect that I must define allocator for mystruct... What should I do to construct own class based on deque and mystruct?
Yours sincerely,
NYWalker
-
November 21st, 2003, 09:51 AM
#2
Simply ...
Code:
typedef deque<mystruct > MEMBERS_DEQUE;
when you use std::queue as follows:
Code:
typedef queue<mystruct, list<mystruct> > MEMBERS_QUEUE;
you are saying to use a list internally in the std::queue code.
(by default it uses a std:eque). A queue is container
adapter - it takes a standard container, and restricts the
operations that can be done on it (and gives the functions
names that are more appropriate for a queue).
If you wanted the internal container in the queue to
be a deque instead of a list you would use :
Code:
typedef queue<mystruct, deque<mystruct> > MEMBERS_DEQUE;
or, since deque is used by default ...
Code:
typedef queue<mystruct> MEMBERS_DEQUE;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|