STL deque problem
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2

Thread: STL deque problem

  1. #1
    Join Date
    Jun 2002

    STL deque problem


    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,

  2. #2
    Join Date
    Aug 2000
    West Virginia
    Simply ...
    typedef deque<mystruct > MEMBERS_DEQUE;
    when you use std::queue as follows:

    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 :

    typedef queue<mystruct, deque<mystruct> > MEMBERS_DEQUE;
    or, since deque is used by default ...
    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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This a survey!

On-Demand Webinars (sponsored)