CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Jun 2002
    Posts
    40

    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

  2. #2
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,721
    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
  •  





Click Here to Expand Forum to Full Width

Featured